【发布时间】:2017-07-18 20:11:24
【问题描述】:
这里我有一个简单的 html 元素,我正在尝试使用 ng-bind-html 绑定到 Html。
但这似乎不起作用:
.controller('foo', function($scope) {
$scope.bar = "<h1>this is bar</h1>";
$scope.bar1 = "<h1> <a ng-href='www.google.com'> this is bar </a></h1>";
});
<div ng-controller="foo">
<div ng-bind-html="bar1"></div>
</div>
如果我使用普通的href,它可以正常工作。谁能解释一下为什么 ng-href 在这种情况下不起作用,或者让我知道如何使它起作用。
【问题讨论】:
-
大家好......正如我提到的,如果我使用href,它可以正常工作。所以我的问题是为什么 ng-href 不能在这里工作。如何让 ng-href 在这里工作
-
ng-href在这里不起作用的原因是因为ng-bind-html没有在绑定的 HTML 中编译任何ng-*指令。href是要走的路,实际上是 the example in the official docs does here。 -
这不是this post@Sajeetharan的副本