search

Home  >  Q&A  >  body text

angular.js - angularjs改变路由时控制器每次都执行两次?

我是angularjs初学者,最近练习过程中遇到一个问题,改变路由后,路由指向的控制器每次都执行两次,有没有遇到过这样问题的朋友,看是哪里出了问题。

怪我咯怪我咯2744 days ago618

reply all(9)I'll reply

  • 某草草

    某草草2017-05-15 16:57:09

    A rough estimate is that you added ng-controller="controller you defined" to your html code

    reply
    0
  • 習慣沉默

    習慣沉默2017-05-15 16:57:09

    I have just used ng’s routing. In fact, in the routing configuration, we configured a controller for different templates. At this time, we no longer need to write it in the template

    ng-controller

    reply
    0
  • 世界只因有你

    世界只因有你2017-05-15 16:57:09

    Looking at your html code, I guess you initialized the control twice somewhere.

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-15 16:57:09

    Has the poster found the cause of this problem now? I have also encountered it. Please give me some advice.

    reply
    0
  • PHPz

    PHPz2017-05-15 16:57:09

    <p class="dv_contain" ng-controller="controller"> This happened many times

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-15 16:57:09

    I defined the controller once in $stateProvider, and then defined it again in html using ng-controller and controller as, and encountered the same situation. This can be solved by using controllerAs directly in $stateProvider.

    reply
    0
  • PHPz

    PHPz2017-05-15 16:57:09

    Have your problem been solved? I also encountered this problem. I have only defined the controller in $stateProvider. I only need to switch it a few times and execute it several times. Each time it corresponds to a different $scope

    reply
    0
  • 高洛峰

    高洛峰2017-05-15 16:57:09

    Excuse me, if I don’t add ng-controller to my page, or should I use ng-click to execute it twice, it will jump twice? If I use ng-click, it will jump once

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-05-15 16:57:09

    ng-view is written twice, just remove one and it will be fine

    reply
    0
  • Cancelreply