我在angular accounts_directives中有这个代码:
(function() {
app.directive('accounts', function() {
return {
restrict: 'E',
templateUrl: '/templates/funds/accounts.html',
scope: {
localValue: '=accounts'
},
controller: function($scope, $state) {
var ctrl;
ctrl = this;
this.state = $state;
if (window.location.hash === "") {
this.state.transitionTo("deposits.currency", {
currency: Account.first().currency
});
}
$scope.accounts = Account.all();
console.log(Account.all());
this.selectedCurrency = window.location.hash.split('/')[2] || Account.first().currency;
this.currentAction = window.location.hash.split('/')[1] || 'deposits';
$scope.currency = this.selectedCurrency;
this.isSelected = function(currency) {
return this.selectedCurrency === currency;
};
this.isDeposit = function() {
return this.currentAction === 'deposits';
};
this.isWithdraw = function() {
return this.currentAction === 'withdraws';
};
this.deposit = function(account) {
ctrl.state.transitionTo("deposits.currency", {
currency: account.currency
});
ctrl.selectedCurrency = account.currency;
return ctrl.currentAction = "deposits";
};
this.withdraw = function(account) {
ctrl.state.transitionTo("withdraws.currency", {
currency: account.currency
});
ctrl.selectedCurrency = account.currency;
return ctrl.currentAction = "withdraws";
};
return (this.event = function() {
return Account.bind("create update destroy", function() {
return $scope.$apply();
});
})();
},
controllerAs: 'accountsCtrl'
};
});
}).call(this);
模板中的链接似乎是这样的:
<a href="#" ng-click="accountsCtrl.deposit(account); $event.preventDefault()" class="ng-binding">Deposit</a>
但点击时,什么都没发生。 当我把accountsCtrl.deposit(帐户);控制结果是Uncaught ReferenceError:accountsCtrl未定义为:1:1
需要明白,为什么即使应用程序中存在代码,accountsCtrl也未定义。 有人可以帮我找到解决方案吗? 也许是一些调试,但尝试找很长时间的解决方案,不知道如何解决它。