2
Using the directive ng-click
to catch an event by clicking one link would be something like:
<a ng-click="call('home')" href="#" title="ir para homepage">Home</a>
But this wouldn’t be the same thing as using onclick="call('home')"
?
A good practice in web development is not to separate each document with its proper functionality? Avoiding that lot of CSS and Javascript inline?
It is possible, for example, to select an element in a similar way to the known $('foo').on('click', function(){});
i and. can access the element of the Javascript file and without filling the HTML
of directives?
For example:
<a ng-model='abrir' href='#'>Abrir</a>
And in the JS:
$scope.abrir.on('click', function(){
call('foo');
});
I think it’s nice to be able to see in the view code the function of a button, but if I don’t use something like Angularjs I have to use
$('foo').on('click', ...
to ensure that the event is signed after the component is rebuilt by an ajax request. Informing the button function in the view is like informing the source of a field value,{{pessoa.nome}}
. This is not the same as mixing html and javascript in the same code. You are not worried for example with the code<input class="btn-primary" type="submit"...
, is? This code has the same concept as your<a ng-click="call('home')"...
, nay?– Caffé
I also see no problems, it is more a doubt of someone who tired of hearing "separates html from Js".
– Renan Gomes
Good practices are more or less like this: "Use UTF-8", "Don’t use Goto", "Don’t put Return in the middle of the function", "Don’t use CSS in HTML", "Don’t leave if without { }"... Honestly, you have to use every single thing where it’s best at the best time and that’s it, as long as you know what you’re doing. Good practices do not provide a lack of knowledge. On the other hand, if you hold the knowledge, no longer need the canned rules called "good practices", so in the end what is really worth understanding how it works, and make a beautiful application, while the guy of good practices is palpitating.
– Bacco
Great resposmentário @Bacco.
– Renan Gomes