IP地址掩码为AngularJS [英] Ip Address mask for AngularJS

查看:210
本文介绍了IP地址掩码为AngularJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道AngularJS一个IP地址掩码插件?

Does Anyone know a ip address mask plugin for AngularJS?

由于我试图用jQuery的输入IP地址控制,但它不工作。当我尝试使用它时,ngModel属性没有得到文本字段的值。在屏幕上,我可以看到价值的文本框里面,但是,如果我做.value的()中的元素,它返回一个值。当我使用的console.log()看到$范围元素的值同样的事情发生。

Because I tried to use the "Jquery Input IP Address Control", but it's not working. When I try to use it, the "ngModel" attribute doesn't get the value of the textfield. In the screen I can see the value inside the textfield, however, if I do ".value()" in the element, it return a "" value. The same thing occur when I see the value of the $scope element by using console.log().

谁能帮我?

谢谢!

编辑:解决

人,问题就解决了​​。

People, problem solved.

我用这个指令可以在 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()。

After I used this directive, the Jquery Plugin worked fine. Probably because now the ngNodel is getting the element.val(). Before, I think it was getting the element.text().

推荐答案

我只是想知道你为什么需要这个摆在首位。怎么样只是用 [ngPattern] [1] 指令和占位符属性?

I'm just wondering why you need this in the first place. What about just using [ngPattern][1] directive and placeholder attribute ?

 <div ng-app='app' ng-controller='myCtrl' ng-form='myForm'>
   <input type='text' ng-model='ip' 
          ng-pattern='/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/' 
          placeholder='xxx.xxx.xxx.xxx'  />
   value : {{ ip }}    
 </div>

的jsfiddle: http://jsfiddle.net/vittore/8mz9uLae/

这篇关于IP地址掩码为AngularJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆