2016-11-06 17 views
1

私のAPIから情報を取得するだけで、うまく応答します。私は私のビューにvm.thisDoctorにアクセスしていますが今

vm.getDoctor = function(id) { 
     $http.get(CONSTANTS.LINK+'/doctors/'+id).success(function(response) { 
      vm.thisDoctor = { 
       name : response.first_name + ' ' + response.last_name, 
       address : response.clinical_address, 
      }; 
      console.log(vm.thisDoctor.address); 
      $state.go('tabs.doctor'); 
     }); 
    } 

console.log(response)意志出力、

Object {id: 1, username: "testmd", first_name: "Juan", 
      last_name: "Dela Cruz", type: "Pediatrician"…} 

コントローラ医師は-this.htmlは、ここに私のapp.js

<a class="item item-thumbnail-left"> 
     <img src="cover.jpg"> 
     <h2>{{ appt.thisDoctor.name }}</h2> 
     <p>{{appt.thisDoctor.address}}</p> 
    </a> 

.state('tabs.doctor', { 
     url: '/doctor/{doctorId}', 
     views: { 
      'tab-appts': { 
      templateUrl: 'templates/appts/doctors-this.html', 
      controller: 'ApptsCtrl as appt' 
      } 
     } 
    }) 

私のcodeは間違っていますか?私は今数時間これをやってきました。

+0

場合 'vm.getDoctor'ですか?データなし引数で '、それは洞察力の先生 – charlietfl

+0

の新しいインスタンスを作成します!!;あなたは' $のstate.go(「tabs.doctor」)を行うので、論理の流れは間違っていますどうもありがとうございます! 本当にお手伝いしました – markhamknight

答えて

2

サーバからの応答を取得した後で、データを失っている理由を、$state.goというビューで変更しています。代わりに、オブジェクトを状態に渡して、以下のようにコントローラーの範囲に戻すことができます。

JS1

vm.getDoctor = function(id) { 
     $http.get(CONSTANTS.LINK+'/doctors/'+id).success(function(response) { 
      vm.thisDoctor = { 
       name : response.first_name + ' ' + response.last_name, 
       address : response.clinical_address, 
      }; 
      console.log(vm.thisDoctor.address); 
      $state.go('tabs.doctor', { 
       args: { 
        data: vm.thisDoctor 
       } 
      }); 
     }); 
    } 

JS2

.state('tabs.doctor', { 
     url: '/doctor/{doctorId}', 
     views: { 
      'tab-appts': { 
      templateUrl: 'templates/appts/doctors-this.html', 
      controller: 'ApptsCtrl as appt' 
      } 
     }, 
     params: { args: {} } // Need to add this 
    }) 

ApptsCtrl$stateParamsを注入)

vm.thisDoctor = ($stateParams.args || {}).data; 
+0

Bruvをありがとうございました@charlietfl' ApptsCtrl ' – markhamknight

+0

いいえupvote @markhamknight? – Antonis

+0

@Antonis私の評判は低いので、私のアップヴォートは反映されません、私のポストをupvoteできますか? – markhamknight

関連する問題