我试图访问范围的值,但它显示为未定义,我需要向我显示用户插入的值。
我的HTML
<div ng-app="myApp" ng-controller="myCtrl as model">
<input type="text" ng-model="model.cero" ng-cero="">
</div>
在JS中
angular
.module("myApp",[])
.controller('myCtrl', function($scope){
var model=this;
})
.directive ('ngCero', function($parse){
var linkFunction =function(scope, element, attrs){
element.bind("keypress", function(event) {
if(event.which === 44 || event.which === 13) {
console.log( $parse(attrs.format));
}
});
};
return{
restrict : 'A',
}
})
答案 0 :(得分:0)
我解决了
angular
.module("myApp",[])
.controller('myCtrl', function($scope){
var model=this;
})
.directive ('ngCero', function($parse){
var linkFunction =function(scope, element, attrs){
element.bind("keypress", function(event) {
if(event.which === 44 || event.which === 13) {
console.log( $parse(attrs.format));
}
});
};
return{
restrict : 'A',
scope:{
cero:"ngModel"
},
link: linkFunction
}
})