我有一个运行块,代码是
.run(['$rootScope', 'formlyConfig', 'appApiCheck', 'licenseExpDateValue',
($rootScope, formlyConfig, appApiCheck, licenseExpDateValue) => {
$rootScope.maskPlaceHolder = '';
formlyConfig.setType({
name: 'maskedInput',
extends: 'input',
template: '<input class="form-control" ng-model="model[options.key]" ng-required="{{licenseExpDateValue.required}}" ng-class="{\'has-error\':licenseExpDateValue.showError}"/>',
defaultOptions: {
ngModelAttrs: {
mask: {
attribute: 'ui-mask'
},
maskPlaceholder: {
attribute: 'ui-mask-placeholder'
}
},
templateOptions: {
maskPlaceholder: $rootScope.maskPlaceholder
}
}
})
}])
以后,我将从服务器获取数据,并将更改$rootScope.maskPlaceholder
,但maskPlaceholder
中的templateOptions
仍然相同。
如何更新maskPlaceHolder
的{{1}}?
感谢
答案 0 :(得分:0)
我会用一次性观察者做到这一点。像
这样的东西.service('UpdateConfig', [ '$rootScope', 'formlyConfig', function ($rootScope, formlyConfig) {
var x = {
updateConfig: function (maskPlaceHolder) {
formlyConfig.setType({
name: 'maskedInput',
extends: 'input',
template: '<input class="form-control" ng-model="model[options.key]" ng-required="{{licenseExpDateValue.required}}" ng-class="{\'has-error\':licenseExpDateValue.showError}"/>',
defaultOptions: {
ngModelAttrs: {
mask: {
attribute: 'ui-mask'
},
maskPlaceholder: {
attribute: 'ui-mask-placeholder'
}
},
templateOptions: {
maskPlaceholder: maskPlaceholder
}
}});
},
watcher: $rootScope.$watch('maskPlaceHolder', function (value) {
x.updateConfig(value);
x.watcher();
});
};
return x;
}])
.run(['$rootScope', 'UpdateConfig', 'appApiCheck', 'licenseExpDateValue',
($rootScope, UpdateConfig, appApiCheck, licenseExpDateValue) => {
UpdateConfig.update('');
});