(function(window, angular, undefined) {
'use strict';
...
ngRouteModule.directive('ngView', ngViewFactory);
...
})(window, window.angular);
<div ng-controller="myCtrl"> <ul> <li><a href="#/a">click a</a></li> <li><a href="#/b">click b</a></li> </ul> <ng-view></ng-view> <!-- <div ng-view ></div> --> </div>
<script type="text/javascript">
angular.module("myApp",["ngRoute"])
.controller("aController",function($scope,$route){
$scope.hello = "hello,a!";
})
.controller("bController",function($scope){
$scope.hello = "hello,b!";
})
.controller("myCtrl",function($scope,$location){
$scope.$on("$viewContentLoaded",function(){
console.log("ng-view content loaded!");
});
$scope.$on("$routeChangeStart",function(event,next,current){
//event.preventDefault(); //cancel url change
console.log("route change start!");
});
})
.config(function($routeProvider, $locationProvider) {
$routeProvider
.when('/a', {
templateUrl: 'a.html',
controller: 'aController'
})
.when('/b', {
templateUrl: 'b.html',
controller: 'bController',
resolve: {
// I will cause a 3 second delay
delay: function($q, $timeout) {
var delay = $q.defer();
$timeout(delay.resolve, 3000);
return delay.promise;
}
}
})
.otherwise({
redirectTo: '/a'
});
});
</script>
<html ng-app="myApp">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="../../bower_components/angular/angular.js"></script>
<script src="../../bower_components/angular-route/angular-route.js"></script>
</head>
<body>
<div ng-controller="myCtrl">
<ul>
<li><a href="#/a">click a</a></li>
<li><a href="#/b">click b</a></li>
</ul>
<ng-view></ng-view>
<!-- <div ng-view ></div> -->
</div>
<script type="text/javascript">
angular.module("myApp",["ngRoute"])
.controller("aController",function($scope,$route){
$scope.hello = "hello,a!";
})
.controller("bController",function($scope){
$scope.hello = "hello,b!";
})
.controller("myCtrl",function($scope,$location){
$scope.$on("$viewContentLoaded",function(){
console.log("ng-view content loaded!");
});
$scope.$on("$routeChangeStart",function(event,next,current){
//event.preventDefault(); //cancel url change
console.log("route change start!");
});
})
.config(function($routeProvider, $locationProvider) {
$routeProvider
.when('/a', {
templateUrl: 'a.html',
controller: 'aController'
})
.when('/b', {
templateUrl: 'b.html',
controller: 'bController',
resolve: {
// I will cause a 1 second delay
delay: function($q, $timeout) {
var delay = $q.defer();
$timeout(delay.resolve, 3000);
return delay.promise;
}
}
})
.otherwise({
redirectTo: '/a'
});
});
</script>
</body>
</html>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有