如何从另一个控制器组件调用控制器功能并将控制权传递给被调用的控制器组件

时间:2016-03-15 01:48:37

标签: javascript angularjs

我有像这样的HTML结构

  <aside class="side" align="left">
     <table onclick="reply_click(event)" ng-controller="TableCtrl" >
           <tr ng-repeat = "table in tables">
             <td><button id = "{{table}}" width = "70">{{table}}</button></td>
           </tr>
     </table>
  </aside>
  <article class="tabs">


      <section id="erd">
        <h2><a href="#erd">ERD</a></h2>
        <p>This content appears on tab ERD.</p>
      </section>

      <section id="col">
        <h2><a href="#col">Columns</a></h2>
    <h2><a href="#col">Columns</a></h2>
    <div id="list" ng-controller="ColCtrl">
      <table>
        <tr>
            <th>Column Name</th>
        </tr>
        <tr ng-repeat="column in columns">
            <td>{{column.name}}</td>
        </tr>
      </table>
    </div> 
      </section>

      <section id="home">
        <h2><a href="#home">Home</a></h2>
        <p>This content appears on tab Home. lfkdgl;k  lkfd;lkg ';lkfg ;lkg 'df;lk ;lk ';lk ';fdlkg ';fdlkg';dflk;ldfkg';lkdlfkdfkglkdf lkjhlsdjhfljdfhlkjdh jh jhkjdhfkjsdhf skjdhf lk h dsfjlkjsdlkfj;dslkfj  dskfj;kj sdfkj fkdj;lfkjsd;lkfj   sdkfj ;slkj sdfj;lskjf   skdj flksjdf ; sdfkj ;sdlkfj dskfj sdkjfhueuu suehu heu he u heu heh ueh ufhu fhe uueh ush uhsudh ue huhuhufheuheu u heiu h euh eh ue </p>
      </section>

  </article>

我使用此SO答案中的建议来呼叫控制器 AngularJS. How to call controller function from outside of controller component

控制器I和呼叫是

angular.element(document.getElementById("list")).scope().loadColumns();

它正确发射。我从TableCtrl组件中的按钮调用它的问题。在loadColumns()被触发后,它转到 TableCtrl组件来循环,这是错误的地方。如何告诉它去正确的地方 ColCtrl区域来循环和填充数据?

谢谢,

0 个答案:

没有答案