当 URL 参数存在于 Angular 时页面加载的方法调用 JS 不工作

Method call on page load when URL params exist in Angular JS is not working

我有以下需求:

读取 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. */

 }

您可能忽略了这些 rest 调用是异步的这一点。

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

更多关于 promises 的信息 -
Angular Promises
Promises Explained