Angularjs usage Problems

Source: Internet
Author: User

1. The template binding mechanism of angularjs seems to be related to its $ HTTP service. If the jquery Ajax return value is assigned to the scope variable of $ scope, the entire binding display is slow, so it is really troublesome.
2. binding the hidden input seems invalid.
3. There is a conflict between binding ng-model of input in angularjs and assigning values to input values. If a model is bound, values cannot be assigned.
4. If the input is not ng-model bound, the input verification mechanism may be faulty: the error message cannot be displayed. Observe the scope and you will find that the error value corresponding to that input does not exist.

5. According to the two conditions 3 and 4, it is best to use ng-model to initialize the form data. When initializing the $ scope variable, you can only copy the first-level subattribute, for example, $ scope. Attr1. If you directly perform secondary attributes, $ scope. Attr1.attr2 value assignment, because the $ scope. The attr1 object has not been created yet, which may cause code errors.

6. There is an article on dependency injection: http://www.cnblogs.com/lcllao/archive/2012/09/23/2699401.html. The recommended method for dependency injection is as follows:

var MyController = function (dep1, dep2) {
     ...
}
MyController. $ Inject = ['dep1', 'dep2'];
MyController.prototype.aMethod = function () {
     ...
}
Unfortunately, this method is not effective for non-Provider dependency injection, so the safer method is the method given in the first 14 pages of the AngularJS book:


var myAppModule = angular.module ('myApp', []);
myAppModule.controller ('TextController',
   function ($ scope) {
      var someText = {};
      someText.message = 'You have started your journey.';
      $ scope.someText = someText;
   });
The most troublesome thing about this method is that you have to add an attribute value such as "myApp" to the ng-app of HTML, and there is a problem in this place that you have to define myapp with JS, otherwise JS will run wrong. Suggest


var myApp = angular.module ('myApp', []);
Such a statement should be placed on the first line of the site's personalized customization code.

Related Article

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.