简体   繁体   English

Angular Js和gapi用于路由应用程序

[英]Angular Js and gapi for routed app

I have a task like in this question. 我有类似这个问题的任务。 But the main difference is that I need two controllers for two different routes. 但是主要的区别是我需要两个不同路径的两个控制器。 Something like two different tables. 有点像两个不同的表。 ../table1 and ../table2. ../table1和../table2。 A data in each table must queried from google cloud endpoints (via gapi). 每个表中的数据必须从Google Cloud端点查询(通过gapi)。 How can I adapt an initialisation sequence for my situation? 如何适应我的情况的初始化顺序? Also, I want have a possibility for deep linking: user may start from /table1 instead of "root path". 另外,我希望可以进行深层链接:用户可以从/ table1开始而不是“ root path”。

You can use 'resolve' to get data from external service, Then inject the names of resolves to controller as same way service get injects. 您可以使用'resolve'从外部服务获取数据,然后将解析的名称注入控制器,就像服务获取注入的方式一样。 Note that you can inject the resolves to the controller that attached to state only. 请注意,您可以将解析方法注入仅附加到state的控制器。 Check the documentation here https://github.com/angular-ui/ui-router/wiki#resolve 在此处查看文档https://github.com/angular-ui/ui-router/wiki#resolve

Eg; 例如;

$stateProvider.state('myState', {
      resolve:{

         googleData:  function($http){
            return $http({method: 'GET', url: '/someUrl'});
         }
      },
      controller: function($scope, googleData)
      {
          $scope.simple = googleData.value;
      }
   })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM