gpt4 book ai didi

javascript - Angular js : How to use resolve when using with require js

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

我在我的项目之一中使用 required-js 和 angular-js 来加载脚本文件。在没有 required-js 的正常情况下,我曾经将 Controller 存储在变量中并将解析绑定(bind)到该变量,如variable.resolve,并且在应用程序配置中我可以提到解析函数。 但是通过使用 required-js 我定义了模块中的所有内容。所以我正在创建 Controller 模块并在那里存储 Controller ,所以我使用 Controller 名称而不是函数。下面是我的配置和 Controller 模块的代码。我不想在配置中编写我的解析逻辑。它应该在 Controller 文件中。我该如何使用 Angular js 。

define(
['angular', 'angular-route', 'controllers', 'directives', 'filters', 'services', 'common-controllers', 'common-directives', 'common-helpdesk-feedback-directives', 'common-constants', 'plunker', 'require'],
function(angular, angularRoute, controllers, directives, filters, services, commonControllers, commonDirectives, commonHelpDeskFeedbackDirectivesModule, plunker) {
var app = angular.module('app', ['ngRoute', 'controllersModule', 'directivesModule', 'filtersModule', 'servicesModule', 'commonControllersModule', 'commonDirectivesModule', 'commonHelpDeskFeedbackDirectivesModule', 'plunkerModule']);
app.init = function() {

setTimeout(function() {
angular.bootstrap(document, ['app']);
}, 2000)
}
app.config(function($routeProvider, $httpProvider) {
$routeProvider
.when('/', {
template: '<div align="center" ><h1>This is default helpdesk page !</h1></div>',
})
.when('/list/:view', {
templateUrl: '../../themes/ngCus/templates/helpdesk/listing.html',
controller: 'listCtrl',
});

});
return app;

}
);

这是我的 Controller 模块

// Define all your controllers here in controller angular module
define(['angular'], function function_name (angular) {
var controller = angular.module('controllers', []);
controller.controller('listCtrl', ['$scope', function($scope){
$scope.message = 'This is dashboard default page !';
}]);
return controller;
});

最佳答案

她是一个答案

在 Controller 文件中

/*reslve function for listCtrl */
controllersModule.resolvelistCtrl = function($q, $timeout) {
/*resolve logic here*/
};

/*reslve function for otherCtrl*/
controllersModule.resolveOtherCtrl = function($q, $timeout) {
/*resolve logic here*/
};

在引导文件中

  define(
['angular', 'angular-route', 'controllers', 'directives', 'filters', 'services', 'common-controllers', 'common-directives', 'common-helpdesk-feedback-directives', 'common-constants', 'plunker', 'require'],
function(angular, angularRoute, controllers, directives, filters, services, commonControllers, commonDirectives, commonHelpDeskFeedbackDirectivesModule, plunker) {
var app = angular.module('app', ['ngRoute', 'controllersModule', 'directivesModule', 'filtersModule', 'servicesModule', 'commonControllersModule', 'commonDirectivesModule', 'commonHelpDeskFeedbackDirectivesModule', 'plunkerModule']);
app.init = function() {

setTimeout(function() {
angular.bootstrap(document, ['app']);
}, 2000)
}
app.config(function($routeProvider, $httpProvider) {
$routeProvider
.when('/', {
template: '<div align="center" ><h1>This is default helpdesk page !</h1></div>',
})
.when('/list/:view', {
templateUrl: '../../themes/ngCus/templates/helpdesk/listing.html',
controller: 'listCtrl',
resolve: {
detailsData: controllers.rsolvelistCtrl,
otherData: controllers.resolveOtherCtrl
/*we can add more here*/
},
});

});
return app;

}
);

关于javascript - Angular js : How to use resolve when using with require js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22908906/

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