私はコントローラの設定と変数の取得に問題があります。 - そのセット[OK]を、私はsharedProperties.get()を呼び出すと、私は私のcommentsCtrlでの記事の使用から "ID" が必要コントローラからAPIを介して変数を取得
app.controller('articleCtrl', function($scope, $http, sharedProperties) {
$http.get('api/article')
.then(function(result){
articleData = result.data;
$scope.article = articleData;
sharedProperties.setProperty(articleData.id);
})});
app.controller('commentsCtrl', function($http, $scope, sharedProperties) {
id = sharedProperties.getProperty();
$http.get('api/article/'+id+'/comments')
.then(function(result){
commentsList = result.data;
$scope.comments = commentsList;
});
:
は私がサービスに
app.service('sharedProperties', function() {
var data = null;
return {
setProperty: function(value) {
data = value;
},
getProperty: function() {
return data;
}
};
});
そして、私のコントローラを作成しますそれでもデフォルトの "null"を返します。
これを修正する方法はありますか?またはコメントコントローラの記事コントローラからgetted idを使用する方法は?
フィードバックに感謝します。
あなたはsharedPropertiesを注入していますか? – rrd
あなたは何を意味するのですか? –
app.controller( 'articleCtrl'、['$ scope'、 '$ http'、sharedProperties、function($ scope、$ http、sharedProperties){})依存関係。 – rrd