1. Generally speaking, it is not recommended but it is still a good choice in $rootScope上面绑定过多的变量,这样一来程序的可维护性就会变差;当然只是不建议,特殊情况特殊处理;比如网站的title标题可能要经常换,所以这个绑定在$rootScope. 2. Angular provides two methods, one is the one you mentioned, and the other is the following:
3. Generally speaking, it is enough to use value和constant.
1. I think in your case you want to use this function in the entire application, then you can write it in the service. Angular's Service is to provide global public methods; the above usage method is to use some External plug-ins, or used to configure some application information, I have written an example here, you can take a look, Portal.
1. Generally speaking, it is not recommended but it is still a good choice in
$rootScope
上面绑定过多的变量,这样一来程序的可维护性就会变差;当然只是不建议,特殊情况特殊处理;比如网站的title
标题可能要经常换,所以这个绑定在$rootScope
.2. Angular provides two methods, one is the one you mentioned, and the other is the following:
3. Generally speaking, it is enough to use
value
和constant
.1. I think in your case you want to use this function in the entire application, then you can write it in the service. Angular's Service is to provide global public methods; the above usage method is to use some External plug-ins, or used to configure some application information, I have written an example here, you can take a look, Portal.
2. The specific code can be seen below:
The order of importing files
index.html
module.js
app.js