0
controller1から状態のparamsを取得できません:他のコントローラ
app.controller('task1Controller',['$scope', 'taskFactory', '$state', function($scope, taskFactory, $state){
$scope.taskData = {};
taskFactory.get().then(function(response){
$scope.jsonData = response.data.data.resultCareGivers[0];
$scope.taskData.fname = $scope.jsonData.firstName;
$scope.taskData.lname = $scope.jsonData.lastName;
$scope.taskData.email = $scope.jsonData.email;
});
$scope.viewDetails = function(){
console.log('taskData before route ', $scope.taskData);
$state.go('view-details', {some: $scope.taskData});
};
}]);
コントローラ2:
app.controller('viewDetailsController', ['$scope', '$stateParams', '$state', function($scope, $stateParams, $state){
console.log('receiveing state params ', $stateParams); //returns null
}]);
HTML:
<div ng-controller="task1Controller">
<div>
<a ng-click="viewDetails()">View Details</a>
</div>
</div>
<div class="container" id="main" ng-controller="viewDetailsController"></div>
コントローラ2つにコントローラ1からの状態のparamsを取得できません。 state.go('params here')
のパラメータを送信しようとしていますが、コントローラ2でその値を取得することができないのはなぜですか(nullを返す)。
設定:
app.config(['$stateProvider', '$urlRouterProvider',
function($stateProvider, $urlRouterProvider){
$urlRouterProvider.otherwise('task1');
var header = {
templateUrl: 'views/header.html',
controller: function ($scope) {
}
};
$stateProvider
.state('task1', {
url: "/task1",
views: {
header: header,
content: {
templateUrl: 'views/task1.html',
controller: function($scope){
console.log('$scope1 ', $scope.image);
}
}
}
})
.state('view-details', {
url: "/view-details",
views: {
header: header,
content: {
templateUrl: 'views/view-details.html',
}
}
});
}]);
$ stateParams.someを使用すると定義されていません – Satyadev
設定ファイルを表示できますか? – Vivz
'app = angular.module( 'techGeneTask'、['ui.router']); ' – Satyadev