5

我正在使用 grunts ng-template 将 html 模板存储在 $templateCache 中。角度文档建议我可以使用这样的模板:

myApp.component('myComponent', {
   templateUrl: 'templateId.html'
});

或像这样:

 myApp.component('myComponent', {
   template: $templateCache.get('templateId.html')
});

有什么区别?我真的不喜欢在每个指令/组件中注入 $templateCache 只是为了使用这个函数。这是关于性能吗?

我读过这篇文章:Angularjs 和 templateUrl 之间的性能差异有多大 ,如果我是对的,那么使用模板(而不是 templateUrl)会快一点。这是唯一的区别吗?

4

0 回答 0