Javascript AngularJS新值未到达指令中
我有一个模态的指令<代码>文件:login.component.jsJavascript AngularJS新值未到达指令中,javascript,angularjs,angularjs-directive,angular-controller,Javascript,Angularjs,Angularjs Directive,Angular Controller,我有一个模态的指令文件:login.component.js (function() { 'use strict'; var app = angular.module('myapp'); app.directive('loginComponent', ['loginService', function(loginService){ return { templateUrl: 'app/components/login/login
(function() {
'use strict';
var app = angular.module('myapp');
app.directive('loginComponent', ['loginService', function(loginService){
return {
templateUrl: 'app/components/login/login.html',
restrict: 'E',
replace: true,
controller: 'homeCrotroller',
link: function ($scope) {
$scope.submit = function() {
$scope.login();
$("#modal-login").modal('hide');
};
$scope.cancel = function() {
$scope.loggingIn = false;
$("#modal-login").modal('hide');
};
$scope.$watch('loggingIn', function() {
if ($scope.loggingIn) {
$("#modal-login").modal('show');
};
});
}
};
}]);
})();
(function() {
'use strict';
var app = angular.module('myapp');
app.controller('homeCrotroller', ['$scope', function($scope){
$scope.loggedIn = false;
$scope.loggingIn = false;
$scope.showLogin = function () {
$scope.loggingIn = true;
};
$scope.logout = function () {
$scope.user = null;
$scope.loggedIn = false;
};
$scope.login = function () {
$scope.loggingIn = false;
$scope.loggedIn = true;
};
}]);
})();
和下一个控制器<代码>文件:home.controller.js
(function() {
'use strict';
var app = angular.module('myapp');
app.directive('loginComponent', ['loginService', function(loginService){
return {
templateUrl: 'app/components/login/login.html',
restrict: 'E',
replace: true,
controller: 'homeCrotroller',
link: function ($scope) {
$scope.submit = function() {
$scope.login();
$("#modal-login").modal('hide');
};
$scope.cancel = function() {
$scope.loggingIn = false;
$("#modal-login").modal('hide');
};
$scope.$watch('loggingIn', function() {
if ($scope.loggingIn) {
$("#modal-login").modal('show');
};
});
}
};
}]);
})();
(function() {
'use strict';
var app = angular.module('myapp');
app.controller('homeCrotroller', ['$scope', function($scope){
$scope.loggedIn = false;
$scope.loggingIn = false;
$scope.showLogin = function () {
$scope.loggingIn = true;
};
$scope.logout = function () {
$scope.user = null;
$scope.loggedIn = false;
};
$scope.login = function () {
$scope.loggingIn = false;
$scope.loggedIn = true;
};
}]);
})();
在我看来,我调用showLogin()
此函数将
$scope.logging
的值更改为true
,只有此值未到达策略。仅到达第一个状态(加载屏幕),即false
除了您两次拼写错误homeCrotroller
之外,我看不出您的代码有任何错误。你确定你在index.html
中同时使用.js
文件吗?你在html文件中使用
吗?是的,我正在使用
。我正在用Grunt、Grunt Nganotate、Grunt contrib concat和UGLIFY生成javascript.min,当我更改变量$scope.logging的值为true并重新充电时,屏幕将正常工作,但单击交替,该值无效。