AngularJS: Constants vs Values

前端 未结 3 1446
离开以前
离开以前 2020-12-04 11:43

As far as I understand the documentation, the only concrete difference between a Constant and a Value is that a Constant can be used during the apps config phase, whereas a

3条回答
  •  隐瞒了意图╮
    2020-12-04 12:04

    True, however, keep in mind if you use an object as a constant, its value can be overridden anytime, anywhere. For example

    const version = '10.0'
    

    can not be changed, if you take a look at the console it even throws an error when changing its value, but

    const config = {
        'version': '8.6'
    }
    

    behaves like a simple value, you can change the the object values anytime, like this:

    config.version = 5
    

    tada, now your version is 5. Same applies for app.const('constant', 'its me')

提交回复
热议问题