검색 컨트롤러와 범주 컨트롤러 및 공유 속성 팩토리가 있습니다. 내 카테고리 컨트롤러에서 여기 당신은 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'가 컨트롤러에 포함되어 있지 않습니다. –
서비스를 컨트롤러에 삽입해야합니다. 이제 '설정'만 주입하고 있습니까? –
질문을 게시 할 때 그냥 잊어 버렸지 만 주입되었습니다. – henrybbosa