私は検索コントローラとカテゴリコントローラと共有プロパティファクトリを持っています。私のカテゴリーコントローラでは、ここであなたはjQueryのコールバックと角度約束を混合している私のコード角度jsでコントローラ間でデータを移動できません
.factory('sharedProperties', function() {
var property = '';
return {
getProperty: function() {
return property;
},
setProperty: function(value) {
property = value;
}
};
})
.controller("SearchCtrl",['config','sharedproperties',function(config,sharedproperties)
{
$scope.search_subCategory_businesses= function()
{
$scope.bus_es = sharedProperties.getProperty();
console.log("sharedProperty hahahaah is",sharedProperties.getProperty()); //logs empty instead of data
angular.forEach($scope.bus_es,function(value,key)
{
$scope.business = value;
if($scope.business.logo == '' || $scope.business.logo==null)
{
$scope.business.logo=config.BaseImageURL+"uploads/defbanner.png"
}else
{
$scope.business.logo=config.BaseImageURL+$scope.business.logo;
}
this.push($scope.business);
},$scope.businesses);
};
//$scope.search_resultsFunction();
$scope.search_subCategory_businesses();
}])
.controller("CategoryCtrl",['config','sharedproperties',function(config,sharedproperties)
{
$scope.getBusinesses=function(sub_category_id)
{
$.get($scope.BaseURL+"classes/util.php?sub_category_id="+sub_category_id+"&transaction=get_businesses",function(results){
alert("results are"+JSON.parse(results));
$scope.bus_es =JSON.parse(results);
sharedProperties.setProperty($scope.bus_es);//successfully sets property
console.log("sharedProperty is",sharedProperties.getProperty());
window.location.href=BaseURL+"search.php";
});
}
}])
あなたのコントローラには 'sharedProperties'が含まれていないようです。 –
サービスをコントローラに注入する必要があります。今あなたは 'config'だけを注入していますか? –
よく質問を投稿するときに忘れていましたが、注入されました – henrybbosa