在指令角度中加载元素

时间:2016-09-26 17:08:09

标签: angularjs angularjs-directive

我想知道如何在输入时插入一个值,当我插入一个字符时,但是通过一个指令,如果我是数字例子:“输入”插入单词enter

<div ng-app="tomatela" ng-controller="somos" ng-model="numero">


 

   angular
.module("tomatela",[])
.controller('somos', function($scope){

})

.directive ('myEnter', function(){
  var linkFunction =function(scope, element, attrs){
     element.bind("keydown", function (event) {
            if(event.which === 13) {
                scope.$apply(function (){
                    scope.$eval(attrs.myEnter);
                    scope.vamos="0,";
                  console.log(event.which);
                });

                event.preventDefault();
            }
        });
  }
  return{
   restrict: 'A',
   scope: {
        cero: '@'
    },
    link: linkFunction
  }

}) 

这里是codepen:http://codepen.io/fernandooj/pen/LRyLYb

0 个答案:

没有答案