angular之两种路由
生活随笔
收集整理的這篇文章主要介紹了
angular之两种路由
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
安裝angular
?npm install -g @angular/cli
?ng new myapp
?ng g component componentName
自帶路由
引入:angular-route.js
<div ng-controller='ctr1'><a href='#home'>首頁(yè)</a> <a href='#mine'>我的</a> <div ng-view></div><div>
?
angular.module('myapp',['ngRoute']).config(['$routerProvider','localProvider',function($routerProvider,$localProvider){$localProvider.hashPrefix('')$routerProvider.when(
'/home',{
templateUrl:'home.html',
controller:'ctr1'
}).when(
'/mine',{
templateUrl:'mine.html',
controller:function($scope){
$scope.name='little-rabbit'
},
}])
otherwise({redirectTo:'/home'}); })
UI.route路由
<div ng-controller='ctr1'><a ui-sref='#home'></a> <a ui-sref='#list'></a> <div ui-view></div><div>
?
angular.module('myapp',['ui.route','angularCSS']) .config(function($stateProvider,$urlRouterProvider){$urlRouterProvider.otherwise('home.html')$stateProvider.state('home',{url:'/home',templateUrl:'home/home.html',css:'home/home.css'})
.state(
name:'list',
url:'/list',
templateUrl:'list/list.html',
css:'list/list.css'}) })
?
轉(zhuǎn)載于:https://www.cnblogs.com/wdxue/p/8341940.html
總結(jié)
以上是生活随笔為你收集整理的angular之两种路由的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: pmp 第六版 模拟卷2疑难问题
- 下一篇: React开发(277):ant des