Angularjs 如何激活状态并将对象传递到新视图?
app.js: 然后,我在(datasourceController)中定义了一个激活onClick的函数 正如我所说,在我的Angularjs 如何激活状态并将对象传递到新视图?,angularjs,angular-ui-router,Angularjs,Angular Ui Router,app.js: 然后,我在(datasourceController)中定义了一个激活onClick的函数 正如我所说,在我的datasource.html视图中,有一个元素click触发submitSelected()函数 在函数中调用时,我可以基于ID成功地从我的服务检索数据 问题是,更改状态后,我无法在视图datasource.list.html中访问它的结果(范围)。在状态配置中添加'param' $scope.submitSelected = function() { if (
datasource.html
视图中,有一个元素click触发submitSelected()
函数
在函数中调用时,我可以基于ID成功地从我的服务检索数据
问题是,更改状态后,我无法在视图
datasource.list.html
中访问它的结果(范围)。在状态配置中添加'param'
$scope.submitSelected = function() {
if (angular.isDefined($scope.selectedSource)) {
$scope.datasource = dataSourcesService.find($scope.selectedSource.id);
$state.go('datasourceList', {datasourceId : datasource});
}
}
并在另一个控制器中使用$stateParams获取值
$stateProvider.state('datasource', {
url: '/datasource',
templateUrl: 'views/datasource.html',
controller: 'datasourceController'
});
$stateProvider.state('datasourceList', {
url: '/datasource/:datasourceId',
templateUrl: 'views/datasource.list.html',
params: ['index', 'anotherKey'],
controller: 'datasourceController'
});
})) 你能添加datasource.list.html的代码吗?datasourceController
datasourceController
只有我已经添加的功能datasource.list.html
有{{datasource}}
我们从哪里得到selectedSource和selectedSource.id?
坦率地说,你不完整的代码阻碍了解决方案。您能添加完整的控制器和视图吗
$stateProvider.state('datasource', {
url: '/datasource',
templateUrl: 'views/datasource.html',
controller: 'datasourceController'
});
$stateProvider.state('datasourceList', {
url: '/datasource/:datasourceId',
templateUrl: 'views/datasource.list.html',
params: ['index', 'anotherKey'],
controller: 'datasourceController'
});
app.controller('datasourceController', function($scope, $stateParams) {
var index = $stateParams.index;
var anotherKey = $stateParams.anotherKey;