I'm having a problem injecting $state
into 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 $state
):
Error: [$ injector: unpr]
Route file:
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 it persists,
Route file:
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] link $ injector / unpr? p0 =% 24stateProvider% 20% 3C-% 20% 24state% 20% 3C-% 20HomeController