角恒定最佳实践 [英] Angular Constant Best Practice
问题描述
我有定义Web服务端点的角度恒
angular.module('MyModule的')。常数('mywebservice_url','http://192.168.1.100)
问题是,对于开发我有一个不同的终点,而分期和生产它的与众不同。每次我试图检查与git我必须手动重置该文件。
- 有什么办法混帐permenantly忽略此文件,但检查出来的文件,而
克隆
或结账
? - 有什么办法可以让动态角头文件从类似环境变量。
请注意:我不想依靠服务器来做到这一点,即我不想用APACH SSI或任何这些技术,因为它会工作只有一组服务器
。-
延迟通过后端处理的注入。我通常只是创建一个名为html页面
pageSettings
哪些值这样的一个全局对象从后端是越来越注入,即环境变量等,并只传递全球pageSettings
对象成角恒
或值
。 -
编译系统注入。如果你没有一个后端,即纯净SPA ...也许你可以把这个构建系统内部,即在一饮而尽或咕噜建筑不同的环境中创建多个任务strong>,并在构建过程中替换值。
I have an angular constant which defines webservice end point
angular.module('myModule').constant('mywebservice_url', 'http://192.168.1.100')
The problem is that for dev I have a different end point while staging and production its different. Every time I try to check in to git I have to manually reset this file.
- Is there any way git permenantly ignore this file but checks out the file while
clone
orcheckout
? - Is there any way I can make angular pickup file dynamically from something like environment variable.
NOTE: I don't want to depend on server to do this, ie I don't want to use apach SSI or any of those technologies as it will work only one set of servers.
Delaying the injection via backend processing. I usually just create a global object on html page called
pageSettings
which values like this is getting injected from the backend, i.e. environment variables, etc. and just pass that globalpageSettings
object into that angularconstant
orvalue
.Build system injection. If you don't have a backend, i.e. pure SPA... maybe you can put this inside your build system, i.e. create multiple task for building the different environments in gulp or grunt and replace that value during the build process.
这篇关于角恒定最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!