<script src="script/angular.min.js"></script> <script src="script/angular-route.min.js"></script>
| 名称 | 类型 | 作用 |
|---|---|---|
| ngView | Directive | 路由的不同模板其实都是插入这个元素里 |
| $routeProvider | Provider | 路由配置 |
| $route | Service | 各个路由的url,view,controller |
| $routeParams | Service | 路由参数 |
<!DOCTYPE html>
<html>
<head>
<meta charset="uft-8"/>
<title></title>
</head>
<script src="script/angular.min.js"></script>
<script src="script/angular-route.min.js"></script>
<body ng-app="color">
<p><a href="#/" rel="external nofollow" rel="external nofollow" >Main</a></p>
<a href="#red" rel="external nofollow" rel="external nofollow" >Red</a>
<a href="#green" rel="external nofollow" rel="external nofollow" >Green</a>
<div ng-view></div>
</body>
<script>
var app = angular.module("color", ["ngRoute"]);
app.config(function ($routeProvider) {
$routeProvider
.when("/", {
templateUrl: "main.html",
controller: 'mainController'
})
.when("/red", {
templateUrl: "red.html",
controller: 'redController'
})
.when("/green", {
templateUrl: "green.html",
controller: 'greenController'
})
.otherwise('/');
});
app.controller('mainController',['$scope',function mainController($scope){
$scope.message='this is main page';
}]);
app.controller('redController',['$scope',function mainController($scope){
$scope.message='this is red page';
}]);
app.controller('greenController',['$scope',function mainController($scope){
$scope.message='this is green page';
}]);
</script>
</html>
<div style="background: red">
{{message}}
</div>
<!DOCTYPE html>
<html>
<head>
<meta charset="uft-8"/>
<title></title>
</head>
<script src="script/angular.min.js"></script>
<script src="script/angular-route.min.js"></script>
<script src="red.js"></script>
<script src="green.js"></script>
<script src="main.js"></script>
<body ng-app="color">
<p><a href="#/" rel="external nofollow" rel="external nofollow" >Main</a></p>
<a href="#red" rel="external nofollow" rel="external nofollow" >Red</a>
<a href="#green" rel="external nofollow" rel="external nofollow" >Green</a>
<div ng-view></div>
</body>
<script>
var app = angular.module("color", ["ngRoute","Module.red","Module.main","Module.green"]);
app.config(function ($routeProvider) {
$routeProvider.otherwise('/');
});
</script>
</html>
angular.module('Module.red', ['ngRoute'])
.config([
'$routeProvider',
function ($routeProvider) {
$routeProvider.when('/red', {
templateUrl: 'red.html',
controller: 'redController'
});
}
])
.controller('redController', [
'$scope',
function ($scope) {
$scope.color='red';
$scope.message = 'This is red page';
}
]);
angular.module('Module.main', ['ngRoute'])
.config([
'$routeProvider',
function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'main.html',
controller: 'mainController'
});
}
])
.controller('mainController', [
'$scope',
function ($scope) {
$scope.message = 'This is main page';
$scope.colors=['blue','yellow','pink'];
}
]);
{{message}}
<br>
<ul>
<li ng-repeat="color in colors">
<a href="#/color/{{color}}" rel="external nofollow" >{{color}}</a>
</li>
</ul>
angular.module('Module.colorId', ['ngRoute'])
.config([
'$routeProvider',
function ($routeProvider) {
$routeProvider
.when('/color/:colorId', {
templateUrl: 'colorId.html',
controller: 'colorIdController'
});
}
])
.controller('colorIdController', [
'$scope','$routeParams',
function ($scope,$routeParams) {
$scope.color = $routeParams.colorId;
$scope.message = 'This is ' +$routeParams.colorId +' page';
}
]);
<div style="background: {{color}}">
{{message}}
</div>
<html>
<head>
<meta charset="uft-8"/>
<title></title>
</head>
<script src="script/angular.min.js"></script>
<script src="script/angular-route.min.js"></script>
<body ng-app="ngst-news">
<div ng-controller="MainController">
<ul>
<li ng-repeat="news in newsAarry">
<a href="#/newsDetail/{{news.id}}" rel="external nofollow" >{{news.title}}</a>
</li>
</ul>
<div ng-view></div>
</div>
</body>
<script src="news.js" charset="UTF-8"></script>
<script src="newsDetail.js" charset="UTF-8"></script>
</html>
var news = angular.module("ngst-news", ["ngst-newsDetail"]);
news.controller("MainController", ["$scope", function ($scope) {
$scope.newsAarry = [{"id": "1", "title": "辽宁人大副主任王阳 浙江宁波市长卢子跃被免职"},
{"id": "2", "title": "今冬小雨缤纷,荔枝园地湿润壮旺荔枝果树,下刀环剥最狠"},
{"id": "3", "title": "百度任原搜索渠道总经理顾国栋为市场执行总监"}];
}]);
{{message}}
var news = angular.module("ngst-newsDetail", ['ngRoute']);
news.config(["$routeProvider",
function ($routeProvider) {
$routeProvider.when("/newsDetail/:newsId", {
templateUrl: 'newsDetail.html',
controller: 'newsDetailController',
resolve: {
content: ['$q', '$timeout', "$route", function ($q, $timeout, $route) {
var deferred = $q.defer();
$timeout(function () {
deferred.resolve('新闻详情 id=' + $route.current.params.newsId);
}, 1000);
return deferred.promise;
}]
}
});
}])
.controller("newsDetailController", ['$scope', 'content',
function ($scope, content) {
$scope.message = content;
}]);
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有