Javascript 呃也是。假设结尾的div不正确是文章中的打字错误。您可以添加指令/组件定义吗?这可能会有帮助。当然,HeaderAccountCtrl的概要也很重要。这表明,帐户属性尚未定义。你也可以列出吗?@MattTester刚刚也添加了控制器。Matt我会尝试使用这
Javascript 呃也是。假设结尾的div不正确是文章中的打字错误。您可以添加指令/组件定义吗?这可能会有帮助。当然,HeaderAccountCtrl的概要也很重要。这表明,帐户属性尚未定义。你也可以列出吗?@MattTester刚刚也添加了控制器。Matt我会尝试使用这,javascript,angularjs,Javascript,Angularjs,呃也是。假设结尾的div不正确是文章中的打字错误。您可以添加指令/组件定义吗?这可能会有帮助。当然,HeaderAccountCtrl的概要也很重要。这表明,帐户属性尚未定义。你也可以列出吗?@MattTester刚刚也添加了控制器。Matt我会尝试使用这个版本,如果它有效,我会接受正确的答案。谢谢。它仍然不能工作,将它从atomico.ready()中移出,并使用绑定到控制器,仍然是相同的问题。不确定那里发生了什么。马特,我会尝试使用这个版本,如果它有效,我会接受正确的答案。谢谢。它仍然不能工
呃也是。假设结尾的
div
不正确是文章中的打字错误。您可以添加指令/组件定义吗?这可能会有帮助。当然,HeaderAccountCtrl
的概要也很重要。这表明,帐户
属性尚未定义。你也可以列出吗?@MattTester刚刚也添加了控制器。Matt我会尝试使用这个版本,如果它有效,我会接受正确的答案。谢谢。它仍然不能工作,将它从atomico.ready()中移出,并使用绑定到控制器,仍然是相同的问题。不确定那里发生了什么。马特,我会尝试使用这个版本,如果它有效,我会接受正确的答案。谢谢。它仍然不能工作,将它从atomico.ready()中移出,并使用绑定到控制器,仍然是相同的问题。不知道那里发生了什么。
<div id='main_app_header' ng-if="ctrl.shouldShowHeader">
<accounts-directive></accounts-directive>
</div>
<div class="account-selector" ng-class="{'account-selector-disabled': haCtrl.accounts.length == 1}">
<select id="account-select" ng-model="haCtrl.current"
ng-options="account as account.name for account in haCtrl.accounts track by account.id"
ng-change="haCtrl.changeAccount()"
ng-disabled="haCtrl.accounts.length == 1">
</select>
</div>
"use strict";
(function() {
var AccountsDirective = function() {
return {
restrict: 'E',
replace: true,
templateUrl: "app/components/header/account/view.html",
controller: 'HeaderAccountCtrl as haCtrl'
};
};
angular.module('mainNgApp').directive('AccountsDirective', AccountsDirective);
})();
"use strict";
(function() {
var HeaderAccountCtrl = function(
$scope,
atomico,
events,
userState
) {
var _this = this;
atomico.ready(function() {
_this.accounts = atomico.metadata['accounts'];
_this.current = atomico.metadata['account'];
});
_this.changeAccount = function(){
atomico.metadata['account'] = _this.current;
userState.setActiveAccountId(_this.current.id, function() {
events.account.change(_this.current);
});
};
};
HeaderAccountCtrl.$inject = [
'$scope',
'atomico',
'events',
'userState'
];
angular.module('mainNgApp').controller('HeaderAccountCtrl', HeaderAccountCtrl);
})();
TypeError: Cannot read property 'appendChild' of undefined
at updateOptions (angular-1.6.4.self-cbf63df….js?body=1:30346)
at Object.ngOptionsPostLink (angular-1.6.4.self-cbf63df….js?body=1:30249)
at angular-1.6.4.self-cbf63df….js?body=1:1347
at invokeLinkFn (angular-1.6.4.self-cbf63df….js?body=1:10427)
at nodeLinkFn (angular-1.6.4.self-cbf63df….js?body=1:9816)
at compositeLinkFn (angular-1.6.4.self-cbf63df….js?body=1:9056)
at nodeLinkFn (angular-1.6.4.self-cbf63df….js?body=1:9810)
at delayedNodeLinkFn (angular-1.6.4.self-cbf63df….js?body=1:10177)
at compositeLinkFn (angular-1.6.4.self-cbf63df….js?body=1:9056)
at compositeLinkFn (angular-1.6.4.self-cbf63df….js?body=1:9059) ""
TypeError: Cannot read property 'value' of undefined
at SelectController.writeNgOptionsValue [as writeValue] (angular-1.6.4.self-cbf63df….js?body=1:30117)
at Object.ngModelCtrl.$render (angular-1.6.4.self-cbf63df….js?body=1:32811)
at ngModelWatch (angular-1.6.4.self-cbf63df….js?body=1:28960)
at Scope.$digest (angular-1.6.4.self-cbf63df….js?body=1:17992)
at Scope.$apply (angular-1.6.4.self-cbf63df….js?body=1:18270)
at HTMLAnchorElement.<anonymous> (angular-1.6.4.self-cbf63df….js?body=1:27000)
at HTMLAnchorElement.dispatch (jquery.self-bd7ddd3….js?body=1:5227)
at HTMLAnchorElement.elemData.handle (jquery.self-bd7ddd3….js?body=1:4879)
TypeError: Cannot read property 'value' of undefined
at SelectController.writeNgOptionsValue [as writeValue] (angular-1.6.4.self-cbf63df….js?body=1:30117)
at Object.ngModelCtrl.$render (angular-1.6.4.self-cbf63df….js?body=1:32811)
at angular-1.6.4.self-cbf63df….js?body=1:30156
at Scope.$digest (angular-1.6.4.self-cbf63df….js?body=1:18000)
at Scope.$apply (angular-1.6.4.self-cbf63df….js?body=1:18270)
at HTMLAnchorElement.<anonymous> (angular-1.6.4.self-cbf63df….js?body=1:27000)
at HTMLAnchorElement.dispatch (jquery.self-bd7ddd3….js?body=1:5227)
at HTMLAnchorElement.elemData.handle (jquery.self-bd7ddd3….js?body=1:4879)
TypeError: Cannot read property 'nodeName' of undefined
at nodeName_ (angular-1.6.4.self-cbf63df….js?body=1:886)
at getBooleanAttrName (angular-1.6.4.self-cbf63df….js?body=1:3497)
at Attributes.$set (angular-1.6.4.self-cbf63df….js?body=1:8650)
at ngBooleanAttrWatchAction (angular-1.6.4.self-cbf63df….js?body=1:22801)
at Scope.$digest (angular-1.6.4.self-cbf63df….js?body=1:18000)
at Scope.$apply (angular-1.6.4.self-cbf63df….js?body=1:18270)
at HTMLAnchorElement.<anonymous> (angular-1.6.4.self-cbf63df….js?body=1:27000)
at HTMLAnchorElement.dispatch (jquery.self-bd7ddd3….js?body=1:5227)
at HTMLAnchorElement.elemData.handle (jquery.self-bd7ddd3….js?body=1:4879)
var AccountsDirective = function() {
return {
restrict: 'E',
replace: true,
templateUrl: "app/components/header/account/view.html",
controller: 'HeaderAccountCtrl as haCtrl',
scope: {},
bindToController: {
accounts: "<"
}
};
};
<accounts-directive accounts="ctrl.accounts"></accounts-directive>