I have this code in controller `
(function () {
'use strict';
var LoginController = function($scope, $http, $timeout,$location,User) {
$scope.user = {};
$scope.flags = {
error: false,
rememberMe: true
};
$scope.signin = function() {
$scope.errorMsg=false;
$scope.successMsg=false;
$scope.flags.loginInProgress=true;
User.login($scope.user.password,$scope.user.email)
.then(function(response) {
if (response.data.success) {
$scope.successMsg=response.data.message;
$scope.flags.loginInProgress=true;
$timeout(function () {
$location.path('shop');
},2000);
}else{
$scope.flags.loginInProgress=false;
$scope.errorMsg=response.data.message;
$scope.flags.error = true;
};
});
};
if (User.isLoggedIn()) {
User.getUser().then(function (response) {
$scope.user=response.data.user;
})
} else {
$location.path('login');
}
$scope.logout=function () {
User.logout();
$timeout(function () {
$location.path('home');
},2000);
};
};
LoginController.$inject = [
'$scope',
'$state',
'$timeout',
'$location',
'User'
];
angular
.module('pharmacy')
.controller('LoginController', LoginController)
}());`
I use ui-router and i use {{user.name}} in page where LoginController is declared it is working but i use {{LoginController.user.name}} where controller is not declared it is doesn't working.
What could be the problem?
$scope
works. you don't have a property called$scope.LoginController
. so{{LoginController}}
wouldn't be valid. aside from that, you say "where controller is not declared"; I would assume this means in HTML that doesn't haveng-controller
, which wouldn't work with angular at all.