AngularJS中常量和值之间的差异

前端之家收集整理的这篇文章主要介绍了AngularJS中常量和值之间的差异前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
常数和价值之间有什么区别?我们能够改变这两个价值观.

var app = angular.module(‘myApp’,[]);
app.constant(‘appName’,‘My App’);
app.value(‘applicationName’,‘Sample’);

解决方法

常量可以放在任何地方,而值不能添加到任何地方.此外,常量不能被装饰器拦截,而值可以被装饰器拦截.

另请参阅:Value and Constants

The difference between a value and a constant service is that the former can only be injected (and thus be used) in a service or a controller while the latter can also be injected into a module configuration function.. (I will discuss the module configuration function in a future post).

猜你在找的Angularjs相关文章