gpt4 book ai didi

node.js - AngularJS 数据绑定(bind)的问题

转载 作者:太空宇宙 更新时间:2023-11-04 02:36:40 25 4
gpt4 key购买 nike

大家好,我遇到了数据绑定(bind)问题。多年来,我一直试图弄清楚为什么我的少数人无法访问服务提供的 global.user。有人能弄清楚发生了什么事吗?预先感谢。最好的问候托马斯

个人资料.html

<section data-ng-controller="MyprofileController">
<h1>{{global.current_User()}}</h1>
</section>

myprofile.js

'use strict';

angular.module('mean.system').controller('MyprofileController', ['$scope', 'Global', function ($scope, Global) {
$scope.global = Global;
$scope.test = 'testcase';}]);

服务

'use strict';

//Global service for global variables
angular.module('mean.system').factory('Global', [
function() {
var current_user = window.user;
return {
current_User: function() {
return current_user;
},
isloggedIn: function() {
return !!current_user;
}
};
}

]);

非常感谢您的帮助。

刚刚发现 Firefox 确实打印了一条错误消息!

 Error: [ng:areq] Argument 'MyprofileController' is not a function, got undefined
http://errors.angularjs.org/1.2.11/ng/areq?
p0=MyprofileController&p1=not%20a%20function%2C%20got%20undefined
minErr/<@http://localhost:3000/lib/angular/angular.js:78
assertArg@http://localhost:3000/lib/angular/angular.js:1363
assertArgFn@http://localhost:3000/lib/angular/angular.js:1374
@http://localhost:3000/lib/angular/angular.js:6774
nodeLinkFn/<@http://localhost:3000/lib/angular/angular.js:6186
forEach@http://localhost:3000/lib/angular/angular.js:310
nodeLinkFn@http://localhost:3000/lib/angular/angular.js:6173
compositeLinkFn@http://localhost:3000/lib/angular/angular.js:5637
publicLinkFn@http://localhost:3000/lib/angular/angular.js:5542
ngViewFillContentFactory/<.link@http://localhost:3000/lib/angular-route/angular-
route.js:915
nodeLinkFn@http://localhost:3000/lib/angular/angular.js:6228
compositeLinkFn@http://localhost:3000/lib/angular/angular.js:5637
publicLinkFn@http://localhost:3000/lib/angular/angular.js:5542
boundTranscludeFn@http://localhost:3000/lib/angular/angular.js:5656
controllersBoundTransclude@http://localhost:3000/lib/angular/angular.js:6248
update@http://localhost:3000/lib/angular-route/angular-route.js:865
Scope.prototype.$broadcast@http://localhost:3000/lib/angular/angular.js:12245
updateRoute/<@http://localhost:3000/lib/angular-route/angular-route.js:556
qFactory/defer/deferred.promise.then/wrappedCallback@http:
//localhost:3000/lib/angular/angu lar.js:10949
qFactory/defer/deferred.promise.then/wrappedCallback@http:
//localhost:3000/lib/angular/angu lar.js:10949
qFactory/ref/<.then/<@http://localhost:3000/lib/angular/angular.js:11035
Scope.prototype.$eval@http://localhost:3000/lib/angular/angular.js:11961
Scope.prototype.$digest@http://localhost:3000/lib/angular/angular.js:11787
Scope.prototype.$apply@http://localhost:3000/lib/angular/angular.js:12067
@http://localhost:3000/lib/angular/angular.js:9202
createEventHandler/eventHandler/<@http://localhost:3000/lib/angular/angular.js:2613
forEach@http://localhost:3000/lib/angular/angular.js:310
createEventHandler/eventHandler@http://localhost:3000/lib/angular/angular.js:2612

<section class="ng-scope" data-ng-view="">

最佳答案

它应该可以工作,并且在我创建的 fiddle 中也可以:http://jsfiddle.net/BernhardW/mLQWs/

window.user = 'John Doe';

angular.module('mean.system', []);

angular.module('mean.system').controller('MyprofileController', function ($scope, Global) {
$scope.global = Global;
$scope.test = 'testcase';
});

angular.module('mean.system').factory('Global', function() {
var current_user = window.user;

return {
current_User: function() {
return current_user;
},
isloggedIn: function() {
return !!current_user;
}
};
});

是否有任何错误显示?

关于node.js - AngularJS 数据绑定(bind)的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21659995/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com