1

我创建了一个链接函数指令,其中包含一个元素ng-include。但是这个元素ng-include不起作用。 有谁知道为什么不工作?AngularJS ng-include直接链接不起作用

app.directive('helloWorld', function() { 
    return { 
     link: function (scope, elem, attrs) {  
      var div = document.createElement('div'); 
      div.setAttribute('ng-include', "page2.html'"); 
      elem.append(div);    
     } 
    }; 
}); 
+0

你有没有错误?路径page2.html是否正确? –

+0

控制台日志plz! – Naveen

+0

路径是正确的。 – bizkit

回答

1

您添加了没有c编译后它就开始工作了。

app.directive('helloWorld',['$compile', function ($compile) { 
    return { 
     link: function (scope, elem, attrs) {  
      var div = document.createElement('div'); 
      div.setAttribute('ng-include', "'page2.html'"); 
      elem.append(div); 

      $compile(div)(scope); 
     } 
    }; 
}]) 

这里是link

0

删除不需要的倒立COMM一个从"page2.html'");"page2.html");

app.directive('helloWorld', function() { 
    return { 
     link: function (scope, elem, attrs) {  
      var div = document.createElement('div'); 
      div.setAttribute('ng-include', "page2.html"); 
      elem.append(div);    
     } 
    }; 
}); 

最好使用http://jshint.com/http://jslint.com/

+0

与删除其也不工作 – bizkit

0

这里北京时间我的例子:plnkr.co/edit/2yuYESDYCyyb0j8ccMvE?p =预览