有人知道AngularJS的IP地址掩码插件吗?
因为我尝试使用“Jquery Input IP Address Control”,但它不起作用。当我尝试使用它时,“ngModel”属性没有获得文本字段的值。在屏幕中,我可以看到文本字段中的值,但是,如果我在元素中执行“.value()”,它会返回一个“”值。当我使用 console.log() 查看 $scope 元素的值时,也会发生同样的事情。
谁能帮我?
谢谢!
编辑:已解决
人,问题解决了。
我使用了http://docs.angularjs.org/api/ng.directive:ngModel.NgModelController中提供的这个指令:
app.directive('contenteditable', function() {
return {
restrict: 'A', // only activate on element attribute
require: '?ngModel', // get a hold of NgModelController
link: function(scope, element, attrs, ngModel) {
if(!ngModel) return; // do nothing if no ng-model
// Specify how UI should be updated
ngModel.$render = function() {
element.html(ngModel.$viewValue || '');
};
// Listen for change events to enable binding
element.bind('blur keyup change', function() {
scope.$apply(read);
});
read(); // initialize
// Write data to the model
function read() {
ngModel.$setViewValue(element.val());
};
}
};
});
使用此指令后,Jquery 插件运行良好。可能是因为现在 ngNodel 正在获取 element.val()。之前,我认为它正在获取 element.text()。