Issue
I have a little problem when building my first AngularJS + C# web app. We have a plugin here (jQuery) which allow us to call a method from any input, and a little warning appears over the input field. The method works likes
user_email.warning('invalid email');
this is very simple to us. The user_email
is an HTML element (input type='text'
) where I want to show the balloon.
But with angularJS I don't know how can I achieve this. I'm from my controller calling the web service. The webservice returns me 'invalid email/email is in use' and I need to send this warning, but inside the controller "I don't know which input is it". It's obvious I have the right name
and id
of field but, it sounds weird if the controller calls this method.
Can I have help about the concepts and if it's a good approach or not?
Solution
Majority of dom manipulation is done from directive. You can define a custom directive and I think that will do the trick.
//Inside directive
var ddo = { //directive definition object
scope : {
msg : '=message'
},
link : function(scope, el, attrs) {
angular.element(el).warning(scope.msg);
}
}
//In html
<input my-directive message="someVar" />
//In controller
controllerScope.someVar = /* call to your web service */
Edit: Adding blogs
http://www.codeproject.com/Articles/607873/Extending-HTML-with-AngularJS-Directives http://blog.brunoscopelliti.com/a-directive-to-manage-file-upload-in-an-angularjs-application
Its not blog but some good directive implementations. Sometimes seeing examples and how they work helps in understanding http://mgcrea.github.io/angular-strap/
Answered By - Rishabh Singhal
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.