使用ng-bind-html在控制器内部无法点击 [英] ng-click not working inside the controller using of ng-bind-html
本文介绍了使用ng-bind-html在控制器内部无法点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的代码下面 - 点击不工作,而我正在检查检查元素ng-click不显示,帮我怎么做
below my code ng-click not working,while i am checking the inspect element ng-click not showing, help me how to do
var app = angular.module('myApp', ['ngSanitize']);
app.controller('myCtrl', function($scope) {
$scope.firstName = "<b ng-click=test(1)>John</b><br><b ng-click=test1(1)>Testing</b>";
$scope.test=function(val)
{
alert(val)
}
$scope.test1=function(val)
{
alert(val)
}
});
<!DOCTYPE html>
<html>
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.min.js"></script>
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular-sanitize.js"></script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<span ng-bind-html=firstName><span>
</div>
</body>
</html>
推荐答案
你背后的原因 ng-click
无法正常工作因为, ng-bind-html
不能编译div,你应该使用 ng-if
那里 OR 编译div并从指令而不是控制器添加该元素。
The reason behind you ng-click
not working is because, ng-bind-html
doens't compile div, You should use ng-if
there OR compile a div and add that element from directive instead of controller.
标记
<div ng-app="myApp" ng-controller="myCtrl">
<span ng-if=showFirstName>
<b ng-click=test(1)>John</b><br><b ng-click=test1(1)>Testing</b>
<span>
</div>
代码
$scope.showFirstName = true;//for showing div
这篇关于使用ng-bind-html在控制器内部无法点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文