简体   繁体   English

在ng-bind-html中使用指令

[英]using directive in ng-bind-html

Im trying to call a directive to change view based on my tab click. 我试图根据我的标签点击调用指令以更改视图。

My directive: 我的指令:

Proj.directive('tab1', function() {
    return {
        restrict:'E',
        templateUrl:'partials/overviewPage.html'
    };
});

and my controller: 和我的控制器:

$scope.selectTab = function(tab){
        if(tab == 'something'){
            $scope.content = '<tab1></tab1>';
        }
    }

and the div Im trying to change 和div我试图改变

<div ng-bind-html="content"></div>

Im trying to click on tab to show overviewPage.html page. 我试图单击选项卡以显示overviewPage.html页面。 But its not working properly. 但是它不能正常工作。

Any suggestion, as I have just started with angularjs 有什么建议,因为我刚开始使用angularjs

Thanks. 谢谢。

This won't work, ng-bind-html will just insert HTML into the DOM tree without triggering AngularJS directives to be processed. 这将行不通, ng-bind-html只会将HTML插入DOM树中,而不会触发AngularJS指令进行处理。

If you want to insert "live" HTML into the DOM, where all the directives are "live" you would have to compile it first ( http://docs.angularjs.org/api/ng .$compile) and then attach to the DOM tree. 如果要将“实时” HTML插入所有指令都处于“实时”状态的DOM中,则必须先对其进行编译( http://docs.angularjs.org/api/ng。$ compile),然后将其附加到DOM树。 This is usually done in a directive. 这通常是在指令中完成的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM