Several problems in the use of ANGULARJS development

Source: Internet
Author: User

1, Angularjs template binding mechanism seems to have a certain relationship with its $http service, if the return value of jquery Ajax is assigned to the scope of the $scope variable, the entire binding shows the rhythm of a slow event, the artifact is really troublesome ah.
2, the binding to hidden input seems invalid: 1.2 After using Ng-value can give hidden input assignment.
3. There is a contradiction between the ng-model binding of input and the value assignment of input in Angularjs. If the model is bound, the value cannot be assigned.
4, input does not do ng-model binding, the validation of the input mechanism will have a problem: the error message does not appear. Looking at scope, you will find that the error value of input does not exist at all.

5, according to 3 and 42 conditions, it is best to initialize the form data with Ng-model, when initializing the $scope variable, only one sub-attribute can be copied, such as $SCOPE.ATTR1, if directly to the two-level attribute, $ SCOPE.ATTR1.ATTR2 is assigned, because the first initialization may $scope.attr1 the object has not actually been created, causing the code to go wrong.

6, on the injection method of dependence, there is an article on the internet to summarize: http://www.cnblogs.com/lcllao/archive/2012/09/23/2699401.html. The recommended methods for dependency injection are:

var function (DEP1, DEP2) {       ...  }   = [' Dep1 ', ' Dep2 '];   function () {       ...  

Unfortunately, this method is not valid for non-provider dependency injection, so the method of insurance is the method of the first 14 pages of the Angularjs book:

var myappmodule = angular.module (' myApp ', []);  Myappmodule.controller (' Textcontroller ',     function($scope) {        var Sometext = {};         = ' You have started your journey. ' ;         = sometext;     });  

The most troublesome thing about this method is that you have to add a "MyApp" attribute value to the HTML Ng-app, and this place has a problem that you have to use the JS definition of MyApp, otherwise JS run error, I personally recommend

var myapp = angular.module (' myApp ', []);  

Such a statement should be placed in the first line of the site personalization code.

7, ng-repeat the array, directly to the data delete array[i] processing does not really delete the role of repeat elements, need to do a processing of this data, and then to the scope of the array assignment, in order to really update the role of the repeat array.

8, data binding asynchronous problem, about ANGULARJS data binding mechanism short description see: http://blog.csdn.NET/dipolar/article/details/ 9291117, because this external monitoring of the binding is implemented asynchronously through external monitoring, if the spatial value following the model assignment is not valid: If the first sentence to a certain input binding model data is assigned, then the second sentence is used Jquery.val () Such a function takes the value of input from the DOM tree is often not the first sentence to give the bound values, because at this time, Angualrjs's external binding monitoring has not yet begun to work.

9, the model of input can not bind the first-level variable of $scope, and finally make an empty object, bind its two-level variable, binding one-level variable in select will not get the value.

10, by the Ng-repeat Web page dynamically generated by the option list, to select the Ng-model assignment interface feedback is not very normal (1.2 version), you can use the ng-selected= "Ng-model_value = = Ng-value" To supplement the correction of this interface to respond to bugs.

11, filter Problem: The Filter object expression is not equal to filter, but the string contains the filter, so equal to the filter must be done with function.

12, Ng-model pass Texteara value of the problem, if it is simply written in the middle of the textera element, do not give the corresponding Ng-model assignment, the page loaded, Textera inside nothing, because did not give the corresponding Ng-model variable assignment, If the background parameter values are passed directly to Ng-model, then some special characters in Texteara will have problems, especially the line break, will directly lead to JS error, if the background to the value of filtering, then return to the Texteara, you have to convert these values back, Otherwise the Textera will show a lot of filter converted characters----This problem has appeared on many large websites in China. It is also cumbersome to ensure that back-end filtering and front-end anti-filtering match each other, so there is a solution to write a few more lines of code, or the server's pre-values in the middle of the Texteara element, through the JQ correlation function to obtain this value, in the controller function to pass this value to Ng-model, This saves the hassle of filtering the conversion. In fact, there are such problems in input, such as the most typical single double quotation marks May and element attribute definition or JS code conflict, but I use Django, its default filtering seems to have solved the problem. In the Java realm, you can introduce ESAPI, the Owasp Security library, to provide a variety of filtering for template output in multiple locations in HTML.

Several problems in the use of ANGULARJS development

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.