Solutions to some problems encountered by angularJS and angularjs

Source: Internet
Author: User

Solutions to some problems encountered by angularJS and angularjs

1. For angularJS $ http. post request, SpringMVC does not receive the parameter value in the background.

The problem is generally: 400 Required String parameter 'rpassword' is not present or other 400 errors

Solution 1: Modify the source code http://my.oschina.net/buwei/blog/191640 (can be detailed to understand the reason the request is not received)

Solution 2: the source code is always difficult to modify. You can use this method to modify the headers and transformRequest parameters of config.

(1) create a globalTransformRequest function

var app = angular.module('myApp');app.config(function ($httpProvider) {    $httpProvider.defaults.transformRequest = function(data){        if (data === undefined) {            return data;        }        return $.param(data);    }});

 

Then create a globalContent-Type header

$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';

 

(2) create a localTransformRequest

var transform = function(data){        return $.param(data);    }    $http.post("/foo/bar", requestData, {        headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},        transformRequest: transform    }).success(function(responseData) {        //do stuff with response    });

 

Reference URLAngularJS-Any way for $ http. post to send request parameters instead of JSON?

2.Scope. $ apply usage

The problem is generally: the two-way Data Binding fails, that is, the $ scope is clearly given to the controller. xxx records cannot be displayed on the page. However, if you click the submit button in the input box or form, the xxx data is displayed.

Solution: add$ Scope. $ apply ()

For example

$ Scope. $ apply (function() {$ Scope. xxx = "your assigned value ";
});

Cause

Generally, you do not need to manually add this code, because angularJS calls this code as needed to achieve the effect of bidirectional data binding.

However, if you reference an external plug-in or others, you can create or update it in the callback function.$ Scope. xxxBecause the external plug-in itself is out of the angularJS scope, the two-way data binding is ineffective here. You can only manually add $ scope. $ apply () to notify the page to obtain data.

3. Because it is a newbie, it comes step by step.


Select echo of AngularJs

I don't know what your aa and some data formats are like. The following is a selected example:
<! DOCTYPE html>
According to AngularJS, I need an example of adding, deleting, querying, modifying, and providing high score guidance.

You have sent a friend to add

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.