相关疑难解决方法(0)

在$ sce.trustAsHtml中渲染指令

我在这里包含了一个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')
        };
});
Run Code Online (Sandbox Code Playgroud)

HTML

<body ng-controller="MainCtrl">
    <div ng-bind-html="trustedHtml"></div>
</body>
Run Code Online (Sandbox Code Playgroud)

angularjs angularjs-directive angularjs-scope

23
推荐指数
2
解决办法
2万
查看次数