UI-Router Multiple Views Single Controller not work

最后都变了- 提交于 2019-11-27 23:16:04
Radim Köhler

Very similar issue: Why controller does not work in UI-router of angularjs?

The point here is:

Controller always belongs to View, never to state.

Other words, to use same type of controller (but two instances for each view), we have to do that kind of declaration:

 $stateProvider.state('Home', {
    url: '/',

    // instead of this
    //controller: "HomeCtrl",

    views: {
      "a": {
        templateUrl: 'templates/a.html',
        controller: "HomeCtrl", // we need this
      },
      "b": {
        templateUrl: 'templates/b.html',
        controller: "HomeCtrl", // and also this
      }
    }
  });

In case, we want to share some stuff among many views, we need different technique than "same controller". See:

How do I share $scope data between states in angularjs ui-router?

Another insight, could be covered here:

scope and controller instantiation with ui router

And including typescript, there is a detailed description and example how all views/states could target some common RootModel

Angular Digest cycle being ran but ng-bind value not updating

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!