在 AngularJS 中使用常量作为过滤器参数
Use constant as filter parameter in AngularJS
我有这样的代码
{{ aDate | bxDate : 'WhitoutTimePart' }}
我想将字符串 'WhitoutTimePart' 更改为常量,这样,如果有一天值发生变化,我就不必在每个 html 文件中进行修改。
类似的东西:
{{ aDate | bxDate : bxdate.whitoutTimePart }}
最好使用枚举或常量...
有什么想法吗?
谢谢
你可以在你的项目中有一个 constants.js 文件,你可以在其中定义这个和其他类似的常量。
(function(){
app.constant('filterParam', 'WhitoutTimePart');
}).call(this);
然后您可以在控制器中导入常量并将其分配给范围变量
(function () {
'use strict';
angular.module('myModule')
.controller('MyController', ['$scope','filterParam', MyController]);
function MyController($scope, filterParam) {
$scope.filterParam = filterParam;
})();
然后终于在你的 html
{{ aDate | bxDate : filterParam }}
希望对您有所帮助
我有这样的代码
{{ aDate | bxDate : 'WhitoutTimePart' }}
我想将字符串 'WhitoutTimePart' 更改为常量,这样,如果有一天值发生变化,我就不必在每个 html 文件中进行修改。
类似的东西:
{{ aDate | bxDate : bxdate.whitoutTimePart }}
最好使用枚举或常量...
有什么想法吗?
谢谢
你可以在你的项目中有一个 constants.js 文件,你可以在其中定义这个和其他类似的常量。
(function(){
app.constant('filterParam', 'WhitoutTimePart');
}).call(this);
然后您可以在控制器中导入常量并将其分配给范围变量
(function () {
'use strict';
angular.module('myModule')
.controller('MyController', ['$scope','filterParam', MyController]);
function MyController($scope, filterParam) {
$scope.filterParam = filterParam;
})();
然后终于在你的 html
{{ aDate | bxDate : filterParam }}
希望对您有所帮助