我想拉一個角度JS指令作爲屬性使用的變量。Angular JS屬性指令採取變量
我們以petFilter
爲例。
HTML:
<input type="text" name="catName" pet-filter='cat'>
<input type="text" name="dogName" pet-filter='dog'>
所以,如果我輸入 '狡猾' 和 '布朗尼' 到兩個輸入端,我要離開:
Foxy is a cat!
Brownie is a dog!
我至今是:
JS:
.directive('petFilter', function(){
return {
restrict: 'A',
require : 'ngModel',
scope : true,
link: function($scope, elem, attrs, ctrl){
$scope.$watch(attrs.ngModel, function() {
var temp = ctrl.$viewValue;
var petType = ????;
outputFunction(temp + 'is a ' + petType + '!');
})
}
};
})
我只是卡在如何設置值petType
。
也許是:VAR petType = scope.model [attrs.pet過濾器]); –