search

Home  >  Q&A  >  body text

angular.js - 动态改变子模块ng-controller

想动态的控制子模块加载的控制器

ng-controller="{{myCtrl}}"

但是这样会报错,系统提示myCtrl不是一个function。

应该是渲染的优先级问题,就是ng-controller渲染太快,后面的变量值还没来的及取到。

求大神指点下,这个要怎么办?

ringa_leeringa_lee2744 days ago502

reply all(3)I'll reply

  • PHP中文网

    PHP中文网2017-05-15 17:00:36

    Why do we need to add double brackets? If myCtrl是个正确controller, just remove the double brackets and write directly.

    reply
    0
  • 巴扎黑

    巴扎黑2017-05-15 17:00:36

    Obviously angular parses the parameters of the ngController directive as strings, not expressions!

    reply
    0
  • PHP中文网

    PHP中文网2017-05-15 17:00:36

    ng-controller="myCtrl" is fine. . .

    reply
    0
  • Cancelreply