Home > Web Front-end > JS Tutorial > body text

Use routing and $location to switch views in angular_AngularJS

WBOY
Release: 2016-05-16 16:18:19
Original
1322 people have browsed it

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.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template