0
I have a problem injecting the $state
in my controller
.
angular.module('myApp', ['ngMaterial'])
.controller('LoginController', function($scope, $rootScope,$state){
$scope.userlogin = "";
$scope.userkey = "";
$scope.access = function(){
console.log("depois")
//$state.go('home');
}
});
The following error is generated (Only when I include the $state
):
Error: [$injector:unpr]
Route archive:
var routerApp = angular.module('myApp', []);
routerApp.config(function($stateProvider, $urlRouterProvider,$state) {
$urlRouterProvider.otherwise('/login');
$stateProvider
.state('login', {
url: '/login',
templateUrl: 'index.html',
controller: 'HomeController'
})
.state('index', {
url: '/index',
templateUrl: 'index.html',
controller: 'HomeController'
});
})
Good afternoon. I made the adjustments but persists,
Rota archive:
var routerApp = angular.module('myApp', []);
routerApp.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/login');
$stateProvider
.state('login', {
url: '/login',
templateUrl: 'login.html',
controller: 'LoginController'
})
.state('index', {
url: '/index',
templateUrl: 'index.html',
controller: 'HomeController'
});
})
Controller:
var app = angular.module('myApp', []);
app.controller('HomeController', function($scope,$rootScope,$state){
console.log('HomeController');
var nome = "teste";
var dateAtual = new Date();
var mensagens = "teste";
$scope.msg = mensagens;
$scope.time = dateAtual;
$scope.nome = nome;
console.log(nome);
console.log(dateAtual);
console.log(mensagens);
})
// - Este controller sem o $state funciona corretamente.
app.controller('LoginController', function($scope,$rootScope){
console.log('LOGINCONTROLLER');
});
angular.min.js:118 Error: [$injector:unpr] http://errors.angularjs.org/1.5.8/$injector/unpr? P0=%24stateProvider%20%3C-%20%24state%20%3C-%20HomeController
Your friend . state('login' is pointing to the Homecontroller, should be pointing to the Logincontroller.
– Diego Garcia
I updated my answer.
– celsomtrindade
mBiz, if the answer solved your problem, be sure to mark it as solved (the "check" icon next to the answer). = D
– celsomtrindade