2017-09-27 7 views

答えて

0

'use strict'; 
function meProfileCtrl(DataService) { 
    var self = this; 
    this.getView = function() { 
     DataService.allData().then(function (response) { 
     self.user = response.data.me_view; 
     console.log(user); 
    }, function(error) { 
     alert("error"); 
    }); 
} 
}; 
angular.module('app').component('meprofile',{ 
     templateUrl :'templates/alldata.html', 
     controller: meProfileCtrl, 
     bindings: { 
      getView: '=', 
      user: '=' 
     } 
    } 
); 

方法{{user.name}}内のデータを割り当てます

コンポーネントで定義することができます。例えば、

angular.module('app').component('meprofile',{ 
     templateUrl :'templates/alldata.html', 
     controller: meProfileCtrl, 
     controllerAs: myctrl,// <-- here 
     bindings: { 
      getView: '=', 
      user: '=' 
     } 
    } 
); 

と使用:あなたのビューでmyctrl.getView()

コンポーネントのドキュメント:https://docs.angularjs.org/guide/component

+0

今私は、「ディレクティブ 『meprofile』で使用される属性で式 『未定義』 『ユーザーが』非割り当て可能です!」を取得します –

+0

@ Jacob.Mこれは今あなたの話題に関連していません。https://docs.angularjs.org/error/$compile/nonassign、あなたはユーザーを追加します。バインディングには「=」が入りますが、定義されていません。 – Fetrarij

+0

解決策が見つかりました。 this.getViewではなくonInit = function() –

関連する問題