一方面,如@ Mark-Rajcok所说,您可以使用私有内部函数:
// at the bottom of your controllervar init = function () { // check if there is query in url // and fire search in case its value is not empty};// and fire it after definitioninit();
您也可以看看ng-init指令。实现将非常像:
// register controller in html<div data-ng-controller="myCtrl" data-ng-init="init()"></div>// in controller$scope.init = function () { // check if there is query in url // and fire search in case its value is not empty};
但是要小心,因为角度文档暗示(自v1.2起)不要
ng-init为此使用。但是imo取决于您应用程序的体系结构。
我
ng-init曾想将后端的值传递给angular应用程序:
<div data-ng-controller="myCtrl" data-ng-init="init('%some_backend_value%')"></div>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)