Summary of common problems in ANGULARJS development learning

Source: Internet
Author: User
Tags lowercase

1. Refresh current page data: $state. Reload

Service.create (data). Then (function (NewItem) {
Flash.success = ' successfully created something ';
Service.fetchall (var force = true). Then (function (services) {
$scope. Services = Services;
$state. Reload ();
});
});

2. After the new save, stay on the Refresh current page, and empty the data: $state. Go ('. ', {}, {reload:true});

Withdrawalsservice.create ({
Withdrawals: $scope. UserList,
Valuekeylist: $scope. Arrayvaluekey
$promise. Then (function (events) {
Msgboxutils.bigbox (events);
Clear the data, refresh the page
$state. Go ('. ', {}, {reload:true});
Save successfully, and print
Print (events);
}, function (Error) {
Msgboxutils.bigbox (Error);
});


3. Delay Refresh the current page: $timeout

Service.create (data). Then (function (NewItem) {
Flash.success = ' successfully created something ';
Service.fetchall (var force = true)
. then (function (services) {
$scope. Services = Services;
}). Then (function () {
Return $timeout (function () {
$state. Go ('. ', {}, {reload:true});
}, 100);
});
});





Angularjs built-in filter explain

Several commonly used filter is built into the angular to simplify our operation.

The filter uses the ' | ' symbol, which is somewhat similar to a pipe in Linux.

1, filter (filtration)

Filter filters the data according to the condition, example:

{{[{name: ' Coolcao ', age:23},{name: ' Lily ', Age:20},{name: ' Tom ', age:22}] | filter: ' Coolcao '}}

Result: [{' Name ': ' Coolcao ', ' age ': 23}]
Here is the filter containing the ' Coolcao ' object, regardless of which attribute contains ' Coolcao ' can be.
If you want to filter precisely, for example, if name is Coolcao, you can use the following:

{{[{name: ' Coolcao ', age:23},{name: ' Lily ', Age:22},{name: ' Tom ', age:22}] | filter:{' name ': ' Coolcao '}}

Note: There should be at least one space between the curly braces used by the filter object and the braces used for ANGULARJS values (that is, the last three curly braces are the penultimate and the penultimate 1, and the 22 curly braces to leave at least one space, otherwise the ANGULARJS will parse the error);

2. Date: Format of dates

In the data returned in the system background, the time field, we may use a timestamp, long type, in the page display is definitely formatted like ' 2012-12-12 12:12:12 ' string, using the date filter can

{{1423130269432 | date: ' YYYY-MM-DD HH:mm:ss '}}

Show Results:
2015-02-05 17:57:49
Note: The timestamp field of a long is in milliseconds, and if the system background is in seconds, the angular is multiplied by 1000 to be converted to milliseconds. This must be a second or a millisecond.

3, Number: digital format

{{3.1415926 | number:1}}
{{3.1415926 | number:2}}
{{ -3.1415926 | number:2}}}
{{3 | number:2}}}
{{0.002 | number:2}}
{{0.009 | number:2}}
{% | number}}
{{1000 | number}}
{{1000 | number:2}}

Results:

3.1
3.14
-3.14
3.00
0.00
0.01
100
1,000
1,000.00

4, ordered by order

{{[{name: ' Coolcao ', age:23},{name: ' Lily ', Age:20},{name: ' Tom ', age:22}] | By: ' Age '}}

Results:

[{' name ': ' Lily ', ' age ': 20},{' name ': ' Tom ', ' Age ': 22},{' name ': ' Coolcao ', ' age ': 23}]


The default is ascending order, if you want to reverse:

{{[{name: ' Coolcao ', age:23},{name: ' Lily ', Age:20},{name: ' Tom ', age:22}] | By: ' Age ': true}}

5, JSON format

{{[{name: ' Coolcao ', age:23},{name: ' Lily ', Age:22},{name: ' Tom ', age:22}] |

Results:

[{' name ': ' Coolcao ', ' Age ':}, {' name ': ' Lily ', ' Age ':}, {' name ': ' Tom ', ' Age ': 22}]

Note: The input is a JS object (not standard JSON), and the output is a standard JSON string (the property name is enclosed in double quotes)

6. Case conversion: Uppercase,lowercase

{' abc ' | uppercase}}

ABC that will output uppercase
Note: Uppercase,lowercase can only filter the string for conversion

7, Currency: The format of the currency
Sometimes we need to show the numbers as currency, and we can use currency to format them.

{{1000 | currency}}
{{1000 | currency: ' Rmb¥ '}}

Show:

$1,000.00
rmb¥1,000.00

8,//parsing backstage to the front desk
, the line-Wrapping problem module directive

Module.filter (' trusthtml ', function ($SCE) {

return function (Input) {

Return $SCE. trustashtml (input);

}

});

Front desk

<article id= "Word-display4" ng-bind-html= "Outsprintdetaillist.strrowallmoney | Trusthtml "></article>

Copyright NOTICE: This article is the original article, without the owner's permission to reprint.

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.