繁体   English   中英

Angular + Webpack:为什么比templte:require(file.html)更好,而不是用templateUrl指定它

[英]Angular + Webpack: Why is better to templte:require(file.html) than to specify it with a templateUrl

我看到了一些使用这种概念通过Angular加载html模板的教程,例如:

$stateProvider.state('stateName', {
   url: 'someState',
   template: require('localFile.html')
}

代替:

$stateProvider.state('stateName', {
   url: 'someState',
   templateUrl: '/path/to/localFile.html'
}

我的猜测是templateUrl使页面进行AJAX调用以需要此页面(我真的不确定为什么需要这样做)。

它真的更好(性能优化)吗?如果是,为什么?

看起来像template: require('localFile.html')依靠RequireJS加载模板; templateUrl: '/path/to/localFile.html'是加载模板的内置方法。

这两个版本都支持延迟加载和缓存,因此我猜没有什么明显的区别-如果您的Angular应用程序中已经有RequireJS,则您可能更喜欢使用它来加载模板。 否则,您可以使用内置的Angular功能。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM