gpt4 book ai didi

javascript - bcbankApp.accsummary 模块 AccountSummaryController 应该有一个 getAccountSummary 函数 在 Angular js 中失败

转载 作者:行者123 更新时间:2023-12-02 22:04:05 25 4
gpt4 key购买 nike

我正在 hackerrank 上使用 Angularjs 开发银行应用程序,我陷入了困境。我试图从帐户摘要 Controller 调用我的函数,但它说我的 Controller 中不存在这样的函数

这是我的代码

AccountSummarycontroller.js

 // Create the controller AccountSummaryController with getAccountSummary function that access accountSummaryService which is already defined in account-summary.service.js. Use $state for Transition from one page to another.


(function() {
'use strict';
var appContr = angular.module('abcbankApp.accountSummary', ['abcbankApp.accountSummaryService']);
appContr.controller('AccountSummaryController', function(AccountSummaryService) {
var ActSumCtrl = this;
// this.AccountSummaryService.getAccountSummary();
ActSumCtrl.accountList = [];
ActSumCtrl.accountList = AccountSummaryService.getAccountSummary();
});

})();

AccountSumaaryService.js

// Create the service AccountSummaryService with getAccountSummary function which should return the account details from data/account-summary.json using $http.get.

(function() {
'use strict';

var appServc = angular.module('abcbankApp.accountSummaryService', []);
appServc.factory('AccountSummaryService', ['$http',
function($http) {
return {
getAccountSummary: function() {
var data;
$http.get('./data/account-summary.json')
.then(function(response) {
data = response.data;
});
return data;
}
};
}]);

})();

但是我收到如下错误

abcbankApp.accsummary 模块 AccountSummaryController 应该有一个 getAccountSummary 函数 FAILED。预期 false 为 true。

Testfile.js

  describe('AccountSummaryController', function() {

it('Controller definition', function() {
expect(AccountSummaryController).toBeDefined();
});



it('should have a getAccountSummary function', function() {
expect(angular.isFunction(AccountSummaryController.getAccountSummary)).toBe(true);
});

});
});

})();

任何帮助将不胜感激。提前致谢

最佳答案

为了回答您的问题,让我们从您的测试用例开始,因为它显示应该定义 AccountSummaryController.getAccountSummary

因此,您应该使用 Controller 名称和函数名称来调用函数

这是修改后的代码

(function() {
'use strict';
var appContr = angular.module('abcbankApp.accountSummary', ['abcbankApp.accountSummaryService']);
appContr.controller('AccountSummaryController', function(AccountSummaryService) {
var ActSumCtrl = this;
// this.AccountSummaryService.getAccountSummary();


ActSumCtrl.accountList = [];
ActSumCtrl.getAccountSummary=function()
{
//move your logic here
}
ActSumCtrl.accountList = AccountSummaryService.getAccountSummary();
});

})();

在评论中让我知道它是否有效

关于javascript - bcbankApp.accsummary 模块 AccountSummaryController 应该有一个 getAccountSummary 函数 在 Angular js 中失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59774199/

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