Home >Web Front-end >JS Tutorial >Use routing and $location to switch views in angular_AngularJS

Use routing and $location to switch views in angular_AngularJS

WBOY
WBOYOriginal
2016-05-16 16:18:191336browse

We can use angular's $route service to define such a thing: for a specific URL pointed to by the browser, angular will load and display a template, and instantiate a controller to provide content for the template.

In the application, you can create routes by calling the functions on the $routeProvider service, and pass the route to be created as a configuration block to these functions. The pseudo code is as follows:

Copy code The code is as follows:

var someModule = angular.module('somemodule',[...module dependencies...])
someModule.config(function($routeProvider){
$routeProvider.
When('url',{controller:aController,templateUrl:'/path/to/template'}).
When(...other...).
       otherwise(...what to do...);
});

The method is very simple and the code is very concise, but it is very practical. I hope you will like it.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn