我正在编写一个过滤器,它将格式化我的联系人窗体中的电话号码但是由于某种原因,输入中的值永远不会更新,我不知道我在做什么错误。角度过滤器不能正常工作
这里是我的HTML:
<div class='form-group'>
<input name='phone' ng-model='home.contact.phone' placeholder='(Area code) Phone' required ng-bind='home.contact.phone | phone' />
</div>
,这里是我的过滤器:
(function() {
'use strict'
angular
.module('Allay.phoneFilter', [])
.filter('phone', function() {
return function (phone) {
if(!phone) return '';
var res = phone + '::' // Since this isn't working, I'm doing something super simple, adding a double colon to the end of the phone number.
return res;
}
});
})();
我不知道,如果你需要这一点,但这里的控制器:
(function() {
'use strict'
angular
.module('Allay', [
'Allay.phoneFilter'
])
.controller('HomeController', function() {
var home = this;
});
})();
如果我在过滤器的'return res'之前添加了一个alert(res),我看到了我期望'123 ::'的值,但是它的输入值是self还只是123
我该怎么做?我在文档中没有看到需要$ scope的任何内容。$ apply()和一个过滤器。 – efarley
好吧,由于您刚刚更改了问题的内容以使我的答案无效,因此我会假设其他答案中的一个会有所帮助。 – Claies