Answer the question
In order to leave comments, you need to log in
Angular how to get just one ajax document?
I want to apologize right away for the MB stupid question and redneck code, but I’ve been studying angular for only 1 day and already in production, I
need to implement data loading of one "document" (json data {doc_name:[],other_data:[]}) by clicking on this link :
<li ng-repeat="doc in order.docs" class="doc">
<div class="row">
<div class="col-md-10">
<a href="#/metal/id={{doc.id}}" ng-click="getDoc(doc.id, doc.type)">{{doc.name}}</a>
</div>
<div class="col-md-1">
<button class="btn btn-xs btn-danger" ng-click="removeDoc(doc.id)"><span class="glyphicon glyphicon-remove"></span></button>
</div>
</div>
</li>
service('Doc', function($http,$location) {
$http(
{
method: 'POST',
url: '/erp/documents/getDocument',
data:{
doc:id
}
}
).
success(function(data, status, headers, config) {
return data;
}).
error(function(data, status, headers, config) {
});
})
app.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/', {
templateUrl: '/makeup/empty.html',
controller: 'DefaultCtrl'
});
$routeProvider.when('/metal/:id', {
templateUrl: '/makeup/metal.html',
controller: 'DocumentsCtrl'
});
$routeProvider.otherwise({
redirectTo: '/'
});
}])
Answer the question
In order to leave comments, you need to log in
angular.module('app').factory('doc', [
'$http',
function ($http) {
return function (id) {
return $http.get(...).then(function (response) {
return response.data;
});
}
}
]);
angular.module('app').controller('MyCtrl', [
'$scope', 'doc',
function ($scope, doc) {
$scope.getDoc = function(id) {
doc(id).then(function (yourDocWillBeHere) {
}
}
}
]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question