About Angular JS's pit

Source: Internet
Author: User

Angular JS is very good very powerful, but note that angular JS is not suitable for the operation of the DOM, although after a version of the update, angular built-in jqlite to facilitate the operation of the DOM, the intention to replace the location of jquery, it is very ulterior motives.

In fact, angular the best place to provide us with a new way of thinking, if you are a novice, want to see what the legendary MVC is a what, in Ember, Backbong, angular ... And so many of the framework of indecision, then recommend first look at angular

Of course the pit is a lot, because immediately 2.* version to appear, so natural 1.* will be slowly eliminated, but do not prevent you to understand a little bit, and in the interview can talk about this

Say a big hole in the angular, where is the command, the pit?

1<div class= "Container" ng-controller= "Ccctrl" >2&LT;H2 class= "Text-center" Toggle-class>lorem ipsum dolor sit amet, consectetur adipiscing elit, sed DoEiusmod tempor incididunt ut labore et dolore magna Aliqua. UT enim ad minim veniam, quis nostrud exercitation Ullamco laboris nisi ut aliquip ex ea commodo consequat.3</div>4 5<script src= "Js/angular.js" ></script>6<script type= "Text/javascript" >7' Use strict '8 varApp = Angular.module (' Ccmodule ', [])9App.controller (' Ccctrl ', [' $scope ',function($scope) {Ten          One     }]) A. directive (' Toggleclass ',function(){ -         return function(Scope, Elem, attrs) { -Elem.bind (' MouseEnter ',function(){ theElem.addclass (' Bg-info ') -             }) -Elem.bind (' MouseLeave ',function(){ -Elem.removeclass ()//the removeclass here are not as powerful as jquery. +             }) -         } +     }) A</script>

Note In H2 I added a directive toggle-class, but in the JS code, I specify this command when the name needs to become Toggleclass, why, that is, the horizontal line split naming and hump method named, both of these naming methods are limited to dead, you change any method will be wrong , that is, if the instruction in the HTML is Toggleclass, and then in JS is Toggleclass, will be wrong, or other naming method, will be wrong, and in the browser console does not show where the error is.

Pit Daddy!!!!

Google forced to add its own naming norms to us, since it is great, so in fact, perhaps Suking is right?

Tai Hang 2, note that I wrote addclass () and Removeclass () in the JS code of the. Directive Directive, both of which are NG-encapsulated jquery methods, but not all encapsulated, so called jqlite, so in elem.removecl () If you do not give the parameters here, the Elem class will not be removed, which makes jquery long-term users of the egg is tight, and console does not error, fuuuuuuuuuuuuuuuuuuc!

So remember next time to write Oh, Elem.removeclass (' Bg-info '), give the parameters, you can.

Angular want to draw a pie, actually already give me feel a little swell of control, there is so little purpose is not clear, what function to the source code Riga, what want to encapsulate, cause angular code very hypertrophy.

If you only take part of the code inside, it really gives you a light, but if you want to control it all, it is recommended that you forget it, not necessary.

So into the pit can, do not fall too deep, after all, Google did not put this angular to its own Gmail or other important places, it means that at any time may abandon the user no longer update

About angular JS pits

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.