好朋友,我在使用Angle with RequireJS时遇到问题。以下是方便的代码结构:
main.js
require.config({
baseUrl: '/',
shim: {
angular: {
exports: "angular"
},
route: {
deps: ["angular"]
},
app:{
deps:['route']
},
controller:{
deps:['app']
}
},
paths: {
//Libery
angular: 'assets/js/lib/angular',
route: 'assets/js/lib/angular-route',
//APP
app: 'app/app',
//Controller
controller: 'app/controller/controller',
},
deps: ['controller']
});
app.js
define('app', ['angular', 'route'], function (angular, route) {
var app = angular.module('app',['ngRoute']);
app.config(function($routeProvider, $locationProvider)
{
$locationProvider.html5Mode(true);
$routeProvider
.when('/', {
templateUrl : 'app/views/home.php',
controller : 'home',
})
.when('/sobre', {
templateUrl : 'app/views/sobre.php',
controller : 'sobre',
})
.when('/contato', {
templateUrl : 'app/views/contato.php',
controller : 'contato',
})
.otherwise ({ redirectTo: '/' });
});
});
controller.js
define('controller', ['app'], function (app) {
app.controller('home', function($rootScope, $location){
$rootScope.activetab = $location.path();
});
app.controller('sobre', function($rootScope, $location){
$rootScope.activetab = $location.path();
});
app.controller('contato', function($rootScope, $location){
$rootScope.activetab = $location.path();
});
});
问题是无法读取未定义的属性'controller' 在RequireJS中,相信依赖是正确的! 谢谢你。