arhan892014-07-07 17:02:12
arhan89, 2014-07-07 17:02:12

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 class="col-md-1">
          <button class="btn btn-xs btn-danger" ng-click="removeDoc(doc.id)"><span class="glyphicon glyphicon-remove"></span></button>

here is a service
service('Doc', function($http,$location) {
            method: 'POST',
            url: '/erp/documents/getDocument',
        success(function(data, status, headers, config) {
             return data;
        error(function(data, status, headers, config) {


and here's a controller
.controller('DocumentsCtrl', function($scope, Doc){
//end Documents controller
$scope.Controler = {
name: 'DocumentsCtrl'
$scope.openDoc = Doc;
$scope.getDoc = function( doc_id, doc_type) {
application settings
app.config(['$routeProvider', function($routeProvider) {
    $routeProvider.when('/', {
        templateUrl: '/makeup/empty.html',
        controller: 'DefaultCtrl'

    $routeProvider.when('/metal/:id', {
        templateUrl: '/makeup/metal.html',
        controller: 'DocumentsCtrl'

        redirectTo: '/'

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Sergey, 2014-07-07

angular.module('app').factory('doc', [
    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) {

arhan89, 2014-07-08

Thank you, good people, they really helped with a working example (if you combine both answers) and gave pointers in which direction to read api, hourly googl-ing did not help, and you got 2 sensible answers in half an hour.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question