0
我想從我的視圖發送值到控制器使用裏面ng-click
函數,然後使用該值傳遞給我的工廠,goint從其餘api鏈接拉動數據,但值IM發送任何回報沒有錯誤,這裏是我的代碼在控制器中使用工廠返回undefined
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js"></script>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, idService) {
$scope.getSo = function (id){
$scope.myIDs = idService.getID(id);
};
});
app.factory('idService', function($http,$q) {
var oGetID = {};
oGetID.getID = function(id) {
var deferred = $q.defer();
$http.get('http://citysdk.dmci.hva.nl/CitySDK/pois/'+id).then(function(response){
deferred.resolve(response.data);
});
return deferred.promise;
};
return oGetID;
});
</script>
</head>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<a href="#" ng-click ="getSo('52527290c5cddb0a7cb654ca');">send variable</a>
{{myIDs.location.address.value}}
</div>
</body>
</html>
我已經盡力了,但它沒有工作,如果你試圖提醒$ scope.myIDs返回undefind – ahmdabos
@ahmdabos放警報內'.then'功能,它會被調用時AJAX成功 –
其返回undefind也 – ahmdabos