Angularjs templateUrl fails to bind attributes inside ng-repeat

后端 未结 5 1192
时光取名叫无心
时光取名叫无心 2020-12-20 01:59

I\'m using directive to display html snippets.

And templateUrl inside the directive, to be able to include snippets as html file.

The directive does not wor

5条回答
  •  独厮守ぢ
    2020-12-20 02:14

    You can use ng-include, watching the attrs. Like this:

    app.directive("myTemplate", function() {
        return {
            restrict: 'E',
            replace: true,
            link: function(scope, elem, attrs) {
                scope.content = attrs.snippet;
                attrs.$observe("snippet",function(v){
                    scope.content = v;
                });
            },
            template: "
    " }; });

提交回复
热议问题