I'm trying to pull in a variable for an angular JS directive used as an attribute.
Let's use petFilter as an example.
HTML:
<input type="text" name="catName" pet-filter='cat'>
<input type="text" name="dogName" pet-filter='dog'>
So that if I enter 'Foxy' and 'Brownie' into the two inputs, I'll get out:
Foxy is a cat!
Brownie is a dog!
What I have so far is:
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 + '!');
})
}
};
})
I'm just stuck at how to set the value of petType.