gpt4 book ai didi

javascript - Angular "angular.js:14110 Error: [ng:areq] Argument ' fn' 不是函数, Controller 实例化时出现未定义的异常

转载 作者:行者123 更新时间:2023-11-28 05:14:43 26 4
gpt4 key购买 nike

我正在使用 Angular 和 TypeScript 设置一个新的 MVC 5 项目,但在实例化 Controller 和服务时遇到问题。当我在 HTML 中包含 ng-controller 时,出现以下错误:

angular.js:14110 Error: [ng:areq] Argument 'fn' is not a function, got undefined

这是我的设置:

app.ts:

module mqApp {
'use strict';

if (typeof (angular) != "undefined") {
var modules;

modules = [];

angular.module("mqApp", modules)
.controller("MasterController", MasterController)
.service("UserService", UserService);
}
}

userService.ts:

module mqApp {

'use strict';

export class UserService {
public static $inject = [
'$scope',
'$http',
'$window'
];

private scope: angular.IScope;
private httpSvc: angular.IHttpService;
private window: angular.IWindowService;

constructor($scope: angular.IScope, $http: angular.IHttpService, $window) {
this.scope = $scope;
this.httpSvc = $http;
this.window = $window;
alert(2);
}

logOff() {
this.httpSvc.get('/Account/LogOff');
this.window.location.href = '/';
}

}
}

masterController.ts:

module mqApp {
'use strict';

export class MasterController {
public static $inject = [
'$scope',
'UserService'
];

private userService: UserService;
private scope: angular.IScope;

contructor($scope: angular.IScope, userService: UserService) {
alert(1);
this.userService = userService;
this.scope = $scope;

}
}
}

最佳答案

MasterController.ts 中的构造函数拼写错误。

关于javascript - Angular "angular.js:14110 Error: [ng:areq] Argument ' fn' 不是函数, Controller 实例化时出现未定义的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41064888/

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