1
Below is the structure of the code to facilitate:
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();
});
});
And the problem is Cannot read Property 'controller' of Undefined At Requirejs I believe the dependencies are correct! Thank you in advance! Thank you.