First, $watch.
Let's talk about angular watch. It can monitor changes in the data model,$scope. $watch (' name ', function (New,old) {}), watch has two parameters, the first one is the name of the watch, The second is a function that executes when the monitored person changes. This function also has two parameters, the first one is the new value, the second is the previous value. Note that the previous value is relative to the new value. When the Watcher is a method, it returns the return value of the method.
Second, create service services
First of all, the role of services, it is equivalent to the extraction of public methods. Again, how to create a service. First understand that angular is a template-based development, so the service is also a template. I personally understand that to create a service template first. How are templates created?
var app=angular.module (' Service ', []); App.service (' MyService ', function () { this.name= ' li '})
Service template The first parameter is the service template name, the second is the function to execute, and angular will automatically create a template object for our new function. This template is the equivalent of encapsulation. Next talk about how to invoke the service.
Iii. Invocation of the service
We've already written the service, and we're going to call it, or that sentence, angular is a template-based development, and when our template calls the service, we're going to create a call template. Create a template and then create a template controller to manipulate the template
var app=angular.module (' MyApp ', [' service ']), App.controller (' Mycon ', [' MyService ', function (MyService) {}])
call the template to create a template first, but the template's environment depends on the service template, so to add service template, note that MyService is not a whole template. The myservice inside the invocation template of the service is the object in the service template .
Iv. Routing
The explanation of the route is the link to the a tag. You can access different pages through different routes, and then configure the routes as explained below. Repeat that sentence, template development. Routing is also a template
var app=angular.module (' Maapp ', [Ngroute]); app. config (' $routeProvider ', function ($routeProvider) { $ Routeprovider.when ( '/ali ', { template: '<Div> on the third floor </ Div > '}) } ). When ('./baidu ', { template: '<Div> on 2 floor </ Div > '})
The routing template relies on a angular-ngroute.js library, so download and rely on it first. Then configure the route config. It has two parameters the first parameter is the value of the anchor point for the fixed notation $routeprovider is followed by a different condition, with when to indicate that a when for a condition it writes the anchor value and corresponding template inlay. When there is a otherwise, indicating that the page does not match the reversed
V. Angular's Ajax
Http.get ('./index.json ') . Then (function (res) { $scope. Data=res.data})
VI. Trivial
Ng-src instead of SRC
Routing in angular, Watch,service and Ajax