I have a problem using require.js and angular.js to load modules asynchronously, and is that many times when making a minimum change I always get the following error:
Uncaught ReferenceError: angular is not defined
main.js
Configuring the javascript files in the main of require.js
require.config({
baseUrl: 'js',
paths : {
angular: 'libs/angular',
ngRoute: 'libs/angular-route',
ngResource: 'libs/angular-resource',
uiRouter: 'libs/angular-ui-router',
index: 'app/index'
},
shim: {
angular: {
exports : 'angular'
}
}
});
require(['index'], function (index){
});
index.js
define(['angular', 'uiRouter'], function (){
angular.module('AppUPC', ['ui-router'])
.controller('formulario', formulario)
.service('obtenerDatos', obtenerDatos)
.config('rutas', rutas);
formulario.$inject = ['$scope', 'obtenerDatos'];
function formulario($scope, obtenerDatos){
$scope.login = function(){
var datos;
datos = {
Usuario: $scope.usuariotxt,
Password: $scope.passwordtxt
};
obtenerDatos.Authentication(datos).then(function (response){
if(response.data){
console.log(response.data);
}else{
console.log(response.status);
};
});
};
};
obtenerDatos.$inject = ['$http', '$httpParamSerializer'];
function obtenerDatos($http, $httpParamSerializer){
function Authentication(datos){
var url = 'http://190.109.185.138/Apipedro/api/login';
return $http.post(url, $httpParamSerializer(datos), {
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
});
};
return {
Authentication: Authentication
};
};
rutas.inject = ['$stateProvider', '$urlRouterProvider'];
function rutas($stateProvider, $urlRouterProvider){
$urlRouterProvider.otherwise("/login");
$stateProvider
.state('login', {
url: '/login',
templateUrl: "templates/login.html",
controller: "formulario"
});
};
});