gpt4 book ai didi

javascript - 如何在运行时更新 angularjs 常量?

转载 作者:行者123 更新时间:2023-11-29 19:09:59 25 4
gpt4 key购买 nike

我在我的应用程序中定义了如下常量,

angular.module('configuration', [])
.constant('Engine_API', 'http://sample.io:1929/')

我在应用程序中使用如下,

var testApp = angular.module('Duot', [ 'configuration']
testApp .controller('userProfileCtrl', function ($scope,Engine_API) {
}

有没有一种方法可以在运行时修改常量并将其设置为新值?

最佳答案

您不能更改 Angular 常量值。但是如果你想改变值,你可以使用 Angular 值提供者而不是常量。

angular.module('configuration', [])
.value('Engine_API', 'http://sample.io:1929/')

关于javascript - 如何在运行时更新 angularjs 常量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39755195/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com