Angular.js Study Notes (iii)

Source: Internet
Author: User

First, filter

1. Uppercase,lowercase Case Conversion
{{"Lower cap string" | uppercase}}//Result: Lower cap string
{"TANK is good" | lowercase}}//Result: TANK is good
2. Date format
{{1490161945000 | date: ' YYYY-MM-DD HH:mm:ss '}}//2017-03-22 13:52:25
3, number formatting (keep decimals)
{{149016.1945000 | number:2}}//reserved two-bit
{{149016.1945000 | number}}//default to 3-bit reserved
4. Currency Currency format
{{currency}}//Result: $250.00
{{] | currency: "Rmb¥"}}//Result: rmb¥250.00
5. Filter Lookup
Input filters can be added to the directive with a pipe character (|) and a filter followed by a colon and a model name.
Filter filter Select a subset from the array
Find the line name for the iphone
{{[{"Age": +, "id": Ten, "Name": "iphone"},
{"Age": "id": one, "name": "Sunm Xing"},
{"Age": $, "id": +, "name": "Test ABC"}
] | filter:{' name ': ' iphone '}}
Filter can also customize the comparison function.
6, LimitTo interception
{{"1234567890" | limitto:6}}//Starting from the front 6 bits
{{"1234567890" | limitto:6,6}}//intercept 6 bits starting from 6th bit
{{"1234567890" | limitto:-4}}//Intercept 4 bits from the back
7. Sort by order
Sort by ID Descending
{{[{"Age": +, "id": Ten, "Name": "iphone"},
{"Age": "id": one, "name": "Sunm Xing"},
{"Age": $, "id": +, "name": "Test ABC"}
] | By: ' ID ': true}}

Ascending row by ID
{{[{"Age": +, "id": Ten, "Name": "iphone"},
{"Age": "id": one, "name": "Sunm Xing"},
{"Age": $, "id": +, "name": "Test ABC"}
] | By: ' ID '}}
9, JSON (do not master, basic use not)

Second, the service

In AngularJS, a service is a function or object that can be used in your AngularJS app.
More than 30 services are built in AngularJS.
$location service, it can use objects that exist in the DOM, similar to window.location objects, but window.location objects have some limitations in AngularJS applications.
AngularJS will always monitor applications, handle event changes, and AngularJS use $location services better than using Window.location objects.
The AngularJS $timeout service corresponds to the JS window.settimeout function.
The AngularJS $interval service corresponds to the JS window.setinterval function.

Create a custom Service
You can create access to custom services that are linked to your module:
To create an access named Hexafy:
App.service (' Hexafy ', function () {
This.myfunc = function (x) {
return x.tostring (16);
}
});
To use access to a custom service, you need to add it individually when you define the filter:
Instance
Use a custom service Hexafy to convert a number to 16 decimal numbers:
App.controller (' Myctrl ', function ($scope, Hexafy) {
$scope. Hex = Hexafy.myfunc (255);
});

Third, routing

Ng in-routing is a separate feature module Ngroute, also a separately released file
-Install or download the Angular-route package
-Introduce this package
-Add Ngroute dependencies in your own module
-routing configuration (Configuring routing rules)
+ rules refer to what kind of request to find what controller
+ [{url: '/SDF ', controller: ' Maincontroller '}]
-write the corresponding controller and view

Instance Resolution 1:
1, loaded the implementation of the router JS file: angular-route.js.
2, contains the Ngroute module as the main application module of the dependent module.
Angular.module (' Routingdemoapp ', [' Ngroute '])
3, use the Ngview directive.
<div Ng-view></div>
The HTML content within the div changes based on the routing changes.
4, configuration $routeProvider, AngularJS $routeProvider used to define routing rules.
Module.config (' $routeProvider ', function ($routeProvider) {
$routeProvider
. When ('/', {Template: ' This is the home page
. When ('/computers ', {Template: ' This is the Computer category page '})
. When ('/printers ', {Template: ' This is the Printer page '})
. Otherwise ({ Redirectto: '/'});
}]); The config function of the
AngularJS module is used to configure routing rules. By using CONFIGAPI, we request that we inject $routeprovider into our configuration functions and use $ROUTEPROVIDER.WHENAPI to define our routing rules. The
$routeProvider provides us with when (Path,object) & Otherwise (object) functions define all routes sequentially, and the function contains two parameters:
The first parameter is a URL or a URL regular rule. The
second parameter is a routing configuration object.

Example resolution 2: (Black technology--self-proclaimed)
<script id= "A_tmpl" type= "Text/ng-template" >
<!--only the type= "Text/javascript" script node will be executed as JS--
<!--script content cannot be displayed on the interface, even if it cannot be executed.

</script>

Module.config ([' $routeProvider ', function ($routeProvider) {
$routeProvider
. When ('/', {templateurl: ' A_tmpl '})
. When ('/computers ', {templateurl: ' A_tmpl '})
. When ('/printers ', {templateurl: ' A_tmpl '})
. Otherwise ({redirectto: '/'});
}]);


Routing Settings object:
AngularJS routing can also be implemented by different templates.
$routeProvider the first parameter of the When function is a URL or url regular rule, and the second parameter is a routing configuration object.
The routing Configuration object syntax rules are as follows:
$routeProvider. When (URL, {
Template:string,
Templateurl:string,
Controller:string, function or array,
Controlleras:string,
Redirectto:string, function,
Resolve:object<key, function>
});
Parameter description:
Template
If we only need to insert simple HTML content in Ng-view, use this parameter:
. When ('/computers ', {Template: ' This is the Computer category page '})
Templateurl:
If we only need to insert an HTML template file in Ng-view, use this parameter:
$routeProvider. When ('/computers ', {
Templateurl: ' views/computers.html ',
});
The above code will get the views/computers.html file contents from the server to insert into Ng-view.
Controller
A function, string, or array type that executes the controller functions on the current template, generating a new scope.
Controlleras:
A string type that specifies an alias for the controller.
Redirectto:
The address of the redirect.
Resolve
Specifies the other modules that the current controller depends on.

Advanced Routing:

The incoming parameter $routeparams in the controller is used to represent the value in the route, passing in the parameter $route, for updating $ in the default in the switch (status)--' var status= $routeParams. Status ' function. Routeparams value is empty
, the code is: $route. Updateparams ({status: '});
If the anchor point is/students/zhangsan
Can be written as/:role/:name to correspond to this anchor point
Will get {Role:students,name:zhangsan} object

# # If you don't write a protocol when you connect to a third-party file:
Http://apps.bdimg.com/libs/angular.js/1.4.7/angular.min.js
↓
<script src= "//apps.bdimg.com/libs/angular.js/1.4.7/angular.min.js" ></script>
If your site is currently deployed in HTTP mode, request
Http://apps.bdimg.com/libs/angular.js/1.4.7/angular.min.js
If it is HTTPS, request
Https://apps.bdimg.com/libs/angular.js/1.4.7/angular.min.js

Angular.js Study Notes (iii)

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.