【发布时间】:2014-01-04 13:31:50
【问题描述】:
我在这里添加了一个 Plunker:http://plnkr.co/edit/4vqV8toHo0vNjtfICtzI?p=preview
我正在尝试向 DOM 添加一个按钮,单击时应该执行绑定到它的函数。在这种情况下,它应该提醒“测试”。这是代码。
控制器
app.controller('MainCtrl', function($scope, $sce) {
$scope.trustedHtml = $sce.trustAsHtml('<button ng-click="testAlert()">Submit</button>');
$scope.testAlert = function () {
alert('testing')
};
});
HTML
<body ng-controller="MainCtrl">
<div ng-bind-html="trustedHtml"></div>
</body>
【问题讨论】:
标签: angularjs angularjs-directive angularjs-scope