Javascript 安圭拉酒店;承诺
我正在研究angularJS,我需要一些帮助 以下是我想做的:Javascript 安圭拉酒店;承诺,javascript,angularjs,Javascript,Angularjs,我正在研究angularJS,我需要一些帮助 以下是我想做的: 我需要构建一个服务来获取和存储我的应用程序属性(通过$http.get()) 我想使用thoses属性有几个弹出窗口(1个弹出窗口=1个指令/控制器..) 我不希望弹出窗口“看到”其余调用(myService.myData应该足够了) 我的问题: 我无法使服务在控制器调用之前检索数据 我想了个办法。。但是它需要一些应用程序更改(在app.js中),我不希望弹出式开发程序这样做 由于我不能这样做,我无法在我的服务/控制器中清洁一
- 我需要构建一个服务来获取和存储我的应用程序属性(通过$http.get())
- 我想使用thoses属性有几个弹出窗口(1个弹出窗口=1个指令/控制器..)
- 我不希望弹出窗口“看到”其余调用(myService.myData应该足够了)
- 我无法使服务在控制器调用之前检索数据
- 我想了个办法。。但是它需要一些应用程序更改(在app.js中),我不希望弹出式开发程序这样做
- 由于我不能这样做,我无法在我的服务/控制器中清洁一些东西
angular.module("myService", []).service("MyService", ['$http', function($http){
this.propertiesInitialized = false;
this.availableLanguages = [];
this.availableResultTypes = [];
this.availableStates = [];
this.availableCrawlTypes = [];
this.dateFormat = "";
this.getProperties = function(callback)
{
$http.get("app/application-properties.json").success(function(JSONProperties) {
this.availableLanguages = JSONProperties.configurations.crawlerLanguages;
this.availableResultTypes = JSONProperties.configurations.resultTypes;
this.availableStates = JSONProperties.configurations.states;
this.availableCrawlTypes = JSONProperties.configurations.crawlTypes;
this.dateFormat = JSONProperties.configurations.dateFormat;
this.propertiesInitialized = true;
});
}
}]);
一个弹出窗口:
angular.module("popup1", ["MyService"])
.controller('Controller1', ['$scope', 'MyService',
function($scope, MyService) {
$scope.languages = MyService.availableLanguages;
$scope.crawlTypes = MyService.availableLanguagesCrawlTypes;
$scope.resultTypes = MyService.availableLanguagesResultTypes;
}]);
你有什么想法吗
谢谢大家! 使用承诺
angular.module("myService", []).service("MyService", ['$http', '$q', function($http, $q){
var deffered = $q.defer();
var theService = this;
theService.propertiesInitialized = deffered.promise;
theService.availableLanguages = [];
theService.availableResultTypes = [];
theService.availableStates = [];
theService.availableCrawlTypes = [];
theService.dateFormat = "";
$http.get("app/application-properties.json").success(function(JSONProperties) {
theService.availableLanguages = JSONProperties.configurations.crawlerLanguages;
theService.availableResultTypes = JSONProperties.configurations.resultTypes;
theService.availableStates = JSONProperties.configurations.states;
theService.availableCrawlTypes = JSONProperties.configurations.crawlTypes;
theService.dateFormat = JSONProperties.configurations.dateFormat;
theService.propertiesInitialized.resolve();
});
}]);
angular.module("popup1")
.controller('Controller1', ['$scope', 'MyService',
function($scope, MyService) {
MyService.propertiesInitialized.then(function(){
$scope.languages = MyService.availableLanguages;
$scope.crawlTypes = MyService.availableLanguagesCrawlTypes;
$scope.resultTypes = MyService.availableLanguagesResultTypes;
});
}]);
使用承诺
angular.module("myService", []).service("MyService", ['$http', '$q', function($http, $q){
var deffered = $q.defer();
var theService = this;
theService.propertiesInitialized = deffered.promise;
theService.availableLanguages = [];
theService.availableResultTypes = [];
theService.availableStates = [];
theService.availableCrawlTypes = [];
theService.dateFormat = "";
$http.get("app/application-properties.json").success(function(JSONProperties) {
theService.availableLanguages = JSONProperties.configurations.crawlerLanguages;
theService.availableResultTypes = JSONProperties.configurations.resultTypes;
theService.availableStates = JSONProperties.configurations.states;
theService.availableCrawlTypes = JSONProperties.configurations.crawlTypes;
theService.dateFormat = JSONProperties.configurations.dateFormat;
theService.propertiesInitialized.resolve();
});
}]);
angular.module("popup1")
.controller('Controller1', ['$scope', 'MyService',
function($scope, MyService) {
MyService.propertiesInitialized.then(function(){
$scope.languages = MyService.availableLanguages;
$scope.crawlTypes = MyService.availableLanguagesCrawlTypes;
$scope.resultTypes = MyService.availableLanguagesResultTypes;
});
}]);
使用承诺
angular.module("myService", []).service("MyService", ['$http', '$q', function($http, $q){
var deffered = $q.defer();
var theService = this;
theService.propertiesInitialized = deffered.promise;
theService.availableLanguages = [];
theService.availableResultTypes = [];
theService.availableStates = [];
theService.availableCrawlTypes = [];
theService.dateFormat = "";
$http.get("app/application-properties.json").success(function(JSONProperties) {
theService.availableLanguages = JSONProperties.configurations.crawlerLanguages;
theService.availableResultTypes = JSONProperties.configurations.resultTypes;
theService.availableStates = JSONProperties.configurations.states;
theService.availableCrawlTypes = JSONProperties.configurations.crawlTypes;
theService.dateFormat = JSONProperties.configurations.dateFormat;
theService.propertiesInitialized.resolve();
});
}]);
angular.module("popup1")
.controller('Controller1', ['$scope', 'MyService',
function($scope, MyService) {
MyService.propertiesInitialized.then(function(){
$scope.languages = MyService.availableLanguages;
$scope.crawlTypes = MyService.availableLanguagesCrawlTypes;
$scope.resultTypes = MyService.availableLanguagesResultTypes;
});
}]);
使用承诺
angular.module("myService", []).service("MyService", ['$http', '$q', function($http, $q){
var deffered = $q.defer();
var theService = this;
theService.propertiesInitialized = deffered.promise;
theService.availableLanguages = [];
theService.availableResultTypes = [];
theService.availableStates = [];
theService.availableCrawlTypes = [];
theService.dateFormat = "";
$http.get("app/application-properties.json").success(function(JSONProperties) {
theService.availableLanguages = JSONProperties.configurations.crawlerLanguages;
theService.availableResultTypes = JSONProperties.configurations.resultTypes;
theService.availableStates = JSONProperties.configurations.states;
theService.availableCrawlTypes = JSONProperties.configurations.crawlTypes;
theService.dateFormat = JSONProperties.configurations.dateFormat;
theService.propertiesInitialized.resolve();
});
}]);
angular.module("popup1")
.controller('Controller1', ['$scope', 'MyService',
function($scope, MyService) {
MyService.propertiesInitialized.then(function(){
$scope.languages = MyService.availableLanguages;
$scope.crawlTypes = MyService.availableLanguagesCrawlTypes;
$scope.resultTypes = MyService.availableLanguagesResultTypes;
});
}]);
我的错,错过了
此
内部成功回调具有另一个上下文并引用另一个对象。我将更新Others的回复:我删除了我的评论,因为我觉得我说得太快了(我是说在深入搜索之前)。这个问题在迪达·乌拉诺夫(Dida_Uranov)的评论中非常明显:)。谢天谢地,我错过了此
内部成功回调具有另一个上下文并引用另一个对象。我将更新Others的回复:我删除了我的评论,因为我觉得我说得太快了(我是说在深入搜索之前)。这个问题在迪达·乌拉诺夫(Dida_Uranov)的评论中非常明显:)。谢天谢地,我错过了此
内部成功回调具有另一个上下文并引用另一个对象。我将更新Others的回复:我删除了我的评论,因为我觉得我说得太快了(我是说在深入搜索之前)。这个问题在迪达·乌拉诺夫(Dida_Uranov)的评论中非常明显:)。谢天谢地,我错过了此
内部成功回调具有另一个上下文并引用另一个对象。我将更新Others的回复:我删除了我的评论,因为我觉得我说得太快了(我是说在深入搜索之前)。这个问题在迪达·乌拉诺夫(Dida_Uranov)的评论中非常明显:)。谢谢