【发布时间】:2015-12-25 03:02:12
【问题描述】:
在不注入服务的情况下,如何将数据从一个视图的控制器传递到另一个视图。我参考了数据、参数、解析、父子概念,但我无法弄清楚。
示例如下:
路由:
$stateProvider
.state('route1', {
url: "/route1",
templateUrl: "route1.html",
controller: "firstCtrl"
})
.state('route2', {
url: "/route2",
templateUrl: "route2.html",
controller: "secondCtrl"
})
观看次数:
route1.html
view 1 : {{firstCtrlValue}}
route2.html
View 2: <input type="text" ng-model="firstCtrlValue"/> <!-- Of course, It won't work -->
<a ui-sref="route1">go to route 1</a>
<a ui-sref="route2">go to route 2</a>
控制器:
.controller('firstCtrl', function($scope) {
$scope.firstCtrlValue = "I am from first";
})
.controller('secondCtrl', function($scope) {
$scope.secondCtrlValue = "Hey I'm from 2nd Ctrl";
});
我想要什么:如果我从 route2 更改模型值,它必须影响 route1。
这里是link
【问题讨论】:
标签: javascript angularjs angular-ui-router angularjs-routing