using directive in ng-bind-html

扶醉桌前 提交于 2019-12-25 16:52:55

问题


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 ng-bind-html="content"></div>

Im trying to click on tab to show overviewPage.html page. But its not working properly.

Any suggestion, as I have just started with angularjs

Thanks.


回答1:


This won't work, ng-bind-html will just insert HTML into the DOM tree without triggering AngularJS directives to be processed.

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. This is usually done in a directive.



来源:https://stackoverflow.com/questions/21723305/using-directive-in-ng-bind-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!