Home  >  Article  >  Web Front-end  >  angular中使用路由和$location切换视图_AngularJS

angular中使用路由和$location切换视图_AngularJS

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

我们可以利用angular的$route服务来定义这样一种东西:对于浏览器所指向的特定URL,angular会加载并显示一个模板,并实例化一个控制器为模板提供内容。

在应用中,你可以通过调用$routeProvider服务上的函数来创建路由,把需要创建的路由当成一个配置块传给这些函数即可。 伪代码如下:

复制代码 代码如下:

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 ...);
});

方法很简单,代码也很简洁,但是却非常实用,希望小伙伴们能够喜欢。

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