【发布时间】:2015-10-05 07:53:57
【问题描述】:
今天我正在努力将我现有的 Angular js ngRoute 基本代码迁移到 ngNewRouter 并卡在组件控制器中。根据新的 apporach 组件控制器没有 $scope,而不是使用“this”。它适用于简单的用例。在特定组件的用例中,我调用 REST API 来获取数据。一切正常,但是当回调发生时,它不会识别“this”定义的对象。以下是代码 sn -p 了解更多详情。
组件控制器调用获取数据:
var ClubonboardingController = function ($location, ApplicationLoaderService, ApplicationConstants, $window, ResourceImplementation, $rootScope) {
//Launch Application
this.launchApplication = function () {
this.cacheLoaded = true;
};
//Method to initialize
this.init = function () {
//show loading screen
this.showLoadingScreen = true;
//Initilize Application cache
ApplicationLoaderService.initilizeApplicationCache($rootScope, "3252345", true, "en_US", function () {
this.launchApplication(); //This throws function not found exception
});
};
//Call init() to initialze the loading.
this.init();
};
app.controller("ClubonboardingController", ClubonboardingController);
ClubonboardingController.$inject = ['$location', 'ApplicationLoaderService', 'ApplicationConstants', '$window', 'ResourceImplementation', '$rootScope'];
问题:在回调代码认为“this”作为全局 javascript 对象后,而不是该控制器的“this”,并且无法找到此控制器中定义的任何内容,并且在 this.launchApplication() 处引发异常; .
请帮忙。
【问题讨论】:
标签: angularjs callback controller angular-routing