How to include one partial into other without creating a new scope?

后端 未结 4 1902
后悔当初
后悔当初 2020-12-02 14:10

I\'ve this routes.

// index.html
One Two
4条回答
  •  一生所求
    2020-12-02 14:22

    You can write your own include directive that does not create a new scope. For example:

    MyDirectives.directive('staticInclude', function($http, $templateCache, $compile) {
        return function(scope, element, attrs) {
            var templatePath = attrs.staticInclude;
            $http.get(templatePath, { cache: $templateCache }).success(function(response) {
                var contents = element.html(response).contents();
                $compile(contents)(scope);
            });
        };
    });
    

    You can use this like:

提交回复
热议问题