AngularJS资源承诺(AngularJS resource promise)
我有一个简单的控制器,使用$资源:
var Regions = $resource('mocks/regions.json'); $scope.regions = Regions.query();
我在一个指令中使用这个控制器(在链接函数中)
var regions = scope.regions;
但地区是未定义的。 这是非常逻辑的调用是异步的。
我的问题是我如何做等待结果和区域是一个数组与所有数据?
UPDATE :
这里的定义是指令
app.directive('ngMap', function() { return { restrict: 'EA', replace: 'true', scope: { }, template: '<div id="map"></div>', controller: 'AccordMapCtrl', link: function(scope, element, attrs) { var regions = scope.regions; console.log(regions); for (var region in regions) {} }; });
I've got a simple controller that use $resource :
var Regions = $resource('mocks/regions.json'); $scope.regions = Regions.query();
I'm using this controller in a directive (in the link function)
var regions = scope.regions;
But regions is undefined. It's pretty logic the call is asynchronous.
My question is how can i do to wait the result and regions be an array with all data ?
UPDATE :
Here the definition of the directive
app.directive('ngMap', function() { return { restrict: 'EA', replace: 'true', scope: { }, template: '<div id="map"></div>', controller: 'AccordMapCtrl', link: function(scope, element, attrs) { var regions = scope.regions; console.log(regions); for (var region in regions) {} }; });
原文:https://stackoverflow.com/questions/19490560
最满意答案
你的app.gradle没有附加。 确保您只引用Pushwoosh库一次。 它看起来像是以某种方式被引用了两次。
Your app.gradle did not attach. Make sure you are referencing the Pushwoosh library only once. It looks like it has been referenced twice somehow.
相关问答
更多-
你的app.gradle没有附加。 确保您只引用Pushwoosh库一次。 它看起来像是以某种方式被引用了两次。 Your app.gradle did not attach. Make sure you are referencing the Pushwoosh library only once. It looks like it has been referenced twice somehow.
-
这是Robospice中的一个已知和固定的问题,由基础的Gradle 2.1问题引起: https : //github.com/stephanenicolas/robospice/issues/365 。 该修补程序将在下一个版本中发布。 您可以通过从所有 Robospice依赖项中排除org.apache.commons:commons-io来解决此问题,并且手动包含commons-io:commons-io:1.3.2 。 喜欢这个: // workaround (https://github.com ...
-
在android工作室导入非android的工作室项目错误[复制](Error in android studio import non-android studio project [duplicate])[2023-09-24]
在project.properties文件中有一个库引用,您需要编辑自己并将其删除。 您可以稍后将其添加回该项目,或者如果这是该库,则可以使用适当的Gradle依赖项。 https://github.com/Bearded-Hen/Android-Bootstrap You have a library reference within the project.properties file that you need to edit yourself and remove. You can add tha ... -
android studio中的null值:packageOutputFile = null(android studio null value in entry: packageOutputFile=null)[2023-11-09]
这可能是一个贪婪的错误。 删除应用程序根目录中的gradle文件夹。 然后打开应用程序,让工作室再次重建gradle。 This maybe a gradle bug. Delete the gradle folder in the root directory of your application. Then open the app, let the studio rebuild the gradle again. -
尝试包含这样的依赖项: compile 'org.testng:testng:6.9.10' compile 'com.google.code.gson:gson:2.6.2' compile 'io.appium:java-client:3.4.1' compile 'org.seleniumhq.selenium:selenium-java:2.53.0' compile 'org.seleniumhq.selenium:selenium-server:2.53.0' 注意:我已经包含了截至目前的最新 ...
-
Android工作室凌空错误(Android studio volley error)[2023-09-09]
尝试在getParams方法之后使用此方法,以便设置内容类型并再次尝试 @Override public MapgetHeaders() throws AuthFailureError { Map params = new HashMap (); params.put("Cont ... -
重复条目:com / google / android / maps / GeoPoint.class(duplicate entry: com/google/android/maps/GeoPoint.class)[2021-12-24]
我做了以下工作: 删除了重复的jar与maven依赖关系 有组织的配置:编译,测试编译,androidTestCompile 确保testCompile依赖关系和编译依赖关系不混合 尝试这个: dependencies { // apply plugin: 'com.google.gms.google-services' // compile 'com.facebook.android:facebook-android-sdk:[4,5)' // compile 'com.goo ... -
首先查看引用您编写的类和方法的第一行的stacktrace: at com.rickhuisman.shoppinglist.CompletedActivity.onCreate(CompletedActivity.java:28) 这告诉我们看看CompletedActivity.java的第28行。 stacktrace中的前一行告诉我这是 Collections.sort(shoppingList); 所以问题在于shoppingList 。 你将不得不挖掘更多来找出原因。 First look ...
-
尝试排除support-v4因为google-play-services已经包含support-v4 compile ('com.google.android.gms:play-services:8.1.0') { exclude group: 'com.android.support', module: 'support-v4' } 如果它不起作用,请清理项目并重建它。 否则,尝试在gradle文件中设置multiDexEnabled defaultConfig { multiDexE ...
-
您可以使用recyclerview或Listview。 对于recycler-view看看以下链接 http://www.androidhive.info/2016/01/android-working-with-recycler-view/ 对于列表视图看到这个链接 http://www.vogella.com/tutorials/AndroidListView/article.html You can either use recyclerview or Listview . For recycler- ...