Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 如何激活状态并将对象传递到新视图?_Angularjs_Angular Ui Router - Fatal编程技术网

Angularjs 如何激活状态并将对象传递到新视图?

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 (

app.js:

然后,我在(datasourceController)中定义了一个激活onClick的函数

正如我所说,在我的
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;