2016-09-30 7 views
1

ナビゲーション/ルーティングにはUI Router Tabsを使用しています。 3つのタブ[ユーザ、アドレスおよびサービス]があります。個々のタブはの状態,url,コントローラおよびテンプレートを持ちます。私はAddressCtrl.jsServiceCtrl.jsにユーザータブからリクエストパラメータ(保存されたオブジェクトのID、姓と名の)[UserCtrl.js]を渡すことができますどのようにUIルータータブを使用してターゲットルートにパラメータを渡す方法

これはどのように達成できますか?

私がこれまで行ってきたことは?

app.js

'use strict'; 

var app = angular.module('xyzApp', [ 'ui.router','ngResource', 'ui.bootstrap', 'ui.router.tabs']); 

app 

    .config(['$stateProvider', '$urlRouterProvider', '$httpProvider', '$interpolateProvider', '$locationProvider', 
      function($stateProvider, $urlRouterProvider, $httpProvider, $interpolateProvider, $locationProvider) { 

     // CSRF Support 
     $httpProvider.defaults.xsrfCookieName = 'csrftoken'; 
     $httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken'; 

     $urlRouterProvider.otherwise('/'); 

     $stateProvider 

      .state('new', { 
       url:   '/', 
       controller: 'MainCtrl', 
       templateUrl: 'partials/base.html' 
      }) 
      .state('new.user', { 
       url:   '/new/user', 
       controller: 'UserCtrl', 
       templateUrl: 'partials/user-tab.html' 
      }) 
      .state('new.address', { 
       url:   '/new/address', 
       controller: 'AddressCtrl', 
       templateUrl: 'partials/address-tab.html' 
      }) 
      .state('new.service', { 
       url:   '/new/service', 
       controller: 'ServiceCtrl', 
       templateUrl: 'partials/service-tab.html', 

      }) 
    }]); 

MainCtrl.js

'use strict'; 
app 
    .controller('MainCtrl', ['$scope', function($scope) { 


     // Inititalise the new personnel page tabs 
     $scope.initialise = function() { 
      $scope.go = function(state) { 
       $state.go(state); 
      }; 

      $scope.personneltabinfo = [ 
       { 
       heading: 'User', 
       route: 'new.user', 
       //params: { 
       // userId: $scope.userId 
       //}, 
       }, 
       { 
       heading: 'Address', 
       route: 'new.address', 

       }, 
       { 
       heading: 'Service', 
       route: 'new.service' 
       } 
      ]; 
     }; 


     $scope.initialise(); 


}]); 

UserCtrl.js

'use strict'; 
app 
    .controller('UserCtrl', ['$scope', '$rootScope', '$http', '$compile', '$timeout', 'userServices', 
     function($scope, $rootScope, $http, $compile, $timeout, userServices) { 


     $scope.userId = ''; 

     $scope.savePerson = function() { 

      console.log("This is userData:" + $scope.userData); 
      // user resource service 
      userServices.addUser($scope.userData) 
      .then(function(data) { 
     // pass $scope.userId to [Account and Service] routes view. 
     // pass firstname and secondname value to [Account and Service] routes view so it’s value can be shown on their panel-title. 
         $scope.userId = data.id; 
       toastr.success('Personnel ' + $scope.baseData.first_name + ' record saved into database'); 
      }, function(data, status, headers, config) { 
       toastr.error('Field Error:' + " Please fill all fields mark with * "); 
      }); 
     }; 

}]); 

私は角の初心者です!

答えて

1

あなたの質問が理解できれば、コントローラから別のコントローラにデータを渡したいと思っています。 、

  • やデータバインディングをhttps://docs.angularjs.org/guide/services
  • $ rootScopeそれが最善の解決策ではありません:Passing data between controllers in Angular JS?

    あなたが使用することができます:

  • 関連する問題