gpt4 book ai didi

angularjs - typescript Angular Controller 构造函数不执行

转载 作者:搜寻专家 更新时间:2023-10-30 21:54:37 25 4
gpt4 key购买 nike

这行代码运行后

    cockpit.controller('shell', shellCtrl);

在我的主模块中,shell Controller 注册到 Angular 应用程序的 _invokeQueue,但 shellCtrl 的构造函数中的代码永远不会触发。为什么不呢?

这是 shellCtrl 的 TypeScript

module cockpit {
'use strict';

export class shellCtrl {
public static $inject = [
'$location', '$rootScope', '$scope',
'localize'
];
public userId = 0;

constructor($location, $rootScope, $scope, localize) {
$scope.vm = this;

$rootScope.$on('localizeResourcesUpdated', function () {
$rootScope.title = localize.getLocalizedString('_appTitle_');
});
//If the userid is null go to login
if (this.userId == 0) {
$location.path('/login');
}
}
}

最佳答案

您需要从 html 调用它。基本上你需要 ng-controller="shell" 基于你的代码。

PS:我有一个关于这个主题的详细视频:http://www.youtube.com/watch?v=WdtVn_8K17E&hd=1

关于angularjs - typescript Angular Controller 构造函数不执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21517788/

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