Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
88
rated 0 times [  92] [ 4]  / answers: 1 / hits: 16525  / 11 Years ago, mon, december 9, 2013, 12:00:00

I have two directives:



// Generated by CoffeeScript 1.6.3
app.directive(focusMe, function() {
return {
scope: {
focus: =focusMe
},
link: function(scope, element) {
return scope.$watch(focus, function(value) {
if (value === true) {
element[0].focus();
return scope.focus = false;
}
});
}
};
});


and:



// Generated by CoffeeScript 1.6.3
app.directive(cleanMe, function() {
return {
scope: {
clean: =cleanMe
},
link: function(scope, element) {
return scope.$watch(clean, function(value) {
if (value === true) {
element[0].value = ;
return scope.clean = false;
}
});
}
};
});


and this input (angularUI):



<input type=text ng-model=addUserSelected typeahead=emp.value for emp in allUsers | filter:$viewValue | limitTo:5 typeahead-editable=false typeahead-on-select=addLine($item.id) focus-me=usersFocusInput clean-me=usersCleanInput>


I get this error:



Error: [$compile:multidir] http://errors.angularjs.org/1.2.3/$compile/multidir?p0=cleanMe&p1=focusMe&p…2%20focus-me%3D%22usersFocusInput%22%20clean-me%3D%22usersCleanInput%22%3E


what do I do wrong?



If I remove the clean-me property from the html it works.



Thanks


More From » angularjs

 Answers
16

I found the solution finally :)



// Generated by CoffeeScript 1.6.3
app.directive(focusMe, function() {
return {
link: function(scope, element, attributes) {
return scope.$watch(attributes.focusMe, function(value) {
if (scope[value] === true) {
element[0].focus();
return scope[attributes.focusMe] = false;
}
});
}
};
});

// Generated by CoffeeScript 1.6.3
app.directive(cleanMe, function() {
return {
link: function(scope, element, attributes) {
return scope.$watch(attributes.cleanMe, function(value) {
if (value === true) {
element[0].value = ;
return scope[attributes.cleanMe] = false;
}
});
}
};
});


In the html usersFocusInput and usersCleanInput are parameters in the scope that is wht I use scope[attributes.focusMe] to get this parameter and change him to false.



<input type=text ng-model=addUserSelected typeahead=emp.value for emp in allUsers | filter:$viewValue | limitTo:5 typeahead-editable=false typeahead-on-select=addLine($item.id) focus-me=usersFocusInput clean-me=usersCleanInput>

[#73841] Friday, December 6, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cassies

Total Points: 112
Total Questions: 99
Total Answers: 96

Location: Mexico
Member since Sun, Jul 25, 2021
3 Years ago
;