简体   繁体   中英

Is it possible to define ng-include, ng-init, ng-controller in controller

<div
    class="row caption-view"
    ng-include="'app/views/inventory/grid-view/part.html'"
    module="subscriber"
    alias="il"
    ng-controller="GridController as il"
    ng-init="il.setGridParams(cse.gridParams.findCation);
    cse.findCaptionGrid = il">
</div>

I have controller ('cse') and in its view i have ng-include with its controller. When everything loaded i can use 'cse.findCaptionGrid' to manipulate with 'GridController' controller.

Problem: 'cse' controller loads and i need to start manipulate with 'GridController' (aka. 'cse.findCaptionGrid') controller. But i cant use 'cse.findCaptionGrid' till ng-include has executed. I tried to use $timeout, but it didnt help. I set timeout to 5000 then it worked.

Question: Is it possible to define 'ng-init="il.setGridParams(cse.gridParams.findCation); cse.findCaptionGrid = il"' part in controller so i can start use it? And in html i just show where this should be shown?

create a directive :

<div my-directive 
  class="row caption-view"
  module="subscriber"
  alias="il"/>


angular.module("yourApp").directive('myDirective', [function(){
   return {
      controller: "GridController as il",
      templateUrl: "app/views/inventory/grid-view/part.html"
   };

}]);

and inside your controller :

this.setGridParams(cse.gridParams.findCation);
cse.findCaptionGrid = this;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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