【问题标题】:Method call on page load when URL params exist in Angular JS is not working当 Angular JS 中存在 URL 参数时页面加载的方法调用不起作用
【发布时间】:2016-04-08 19:04:02
【问题描述】:

我有以下要求:

读取 URL 参数,加载页面上的 2 个下拉菜单并使用 URL 参数中的值预填充它们。然后使用下拉值调用方法来加载网格。

这是我到现在为止所做的:

在控制器上,我使用 $location.search() 检查参数,如果存在,则调用一些方法。我将此代码放在控制器的末尾。但是,当调用控制器内部的方法时,REST 调用不会通过,而是在控制器总负载发生后调用。

感谢任何帮助!

示例场景:

 function abc(){/*some code*/}
 function xyz(){/*some code*/}
 function abd(){/*some code*/}
 if(typeof $location.search().paramaName !=undefined){
  /*Read URL params. preselect the current drop down by calling abc,xyz.use the values to call abd() which makes a REST API call to load the data on the page. */

 }

【问题讨论】:

    标签: angularjs angularjs-scope angular-controller


    【解决方案1】:

    您可能错过了这些休息调用是异步的这一点。

    您可以在返回的 promise 对象的 then() 方法中包含对这些函数的调用;这将在异步调用完成后执行。

    更多关于这里的承诺 -
    Angular Promises
    Promises Explained

    【讨论】:

      猜你喜欢
      • 2016-08-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多