2017-06-21 58 views
0
I am getting details from an api which is an array of object. 

    (function() { 
    'use strict'; 
    angular.module('myApp.components') 
     .directive('abc', abc); 

    abc.$inject = ['$http', '$timeout', 'ApiServices']; 

    function abc($http, $timeout, ApiServices) { 
     return { 
      restrict: 'EA', 
      scope: {}, 
      link: function (scope, el, attrs) { 
       $('#bankMaster').on('hide.bs.modal', function() { 
        scope.list=[]; 
       }); 
       $('#bankMaster').on('shown.bs.modal', function() { 
        scope.list=[]; 

        scope.getAllDetails = function() { 
         ApiServices.getAllDetails().then(
          function (response) { 
           scope.list = response.data; 
          }, 
          function (err) { 
           // Handle error here 
           console.log('Error' + JSON.stringify(err.data)); 
          }); 
        }; 
      }, 
      templateUrl: 'js/folder/abc.html' 
     }; 
    } 

})(); 

我试图显示在前端的这些数据: -如何显示angularJs的表单数据

<form class="form-horizontal" name="abcForm"> 
      <div class="form-group"> 
       <label>User Type :</label> 
        <label>{{list[0].userType}}</label> 
       <label>User Code :</label> 
        <label>{{list[0].userCode}}</label> 
       <label>Cost Price :</label> 
        <label>{{list[0].costPrice}}</label> 
      </div> 
      <div class="form-group"> 
       <label>Purchase Date :</label> 
        <label>{{list[0].date}}</label> 
       <label>Taxes :</label> 
        <label>{{list[0].taxes}}</label> 
       <label>Other : {{list[0].other}}</label> 
      </div> 
</form> 

但没有得到displayed.My语法是正确的,但我觉得我在做一些其他的我无法理解的错误。任何人都可以告诉我这段代码有什么问题吗?

我Apiservices代码: -

(function() { 
    'use strict'; 

    angular 
     .module('myApp.core') 
     .factory('ApiServices', ApiServices); 

    /* @ngInject */ 
    function ApiServices($q, $rootScope, $http) { 
     return { 
      getAllDetails: getAllDetails 
     }; 
      function getAllDetails() { 
      return $http({ 
       method: 'GET', 
       url: '/api/abc/data/' 
      }); 
     } 



    }; 
})(); 
+0

ca n u提供一些模拟数据的response.data –

+0

abc指令在你的html? – Max

+0

请提供ApiServices代码 – madhur

回答

0

你需要注入模块主模块'myApp.components'中像下面 angular.module('myApp.components', ['myApp.core']) 并确保模块首次加载。 让我知道如果你还有其他问题

+0

我不认为这是一个问题,因为我在其他指令中使用Apiservices并显示相应的htmls数据,这工作正常。 –

+0

如果你没有信心,你不应该投票回答。我非常确定该模块应该注入主模块,以便在其指令和控制器中使用它。删除该投票并首先学习角度。首先你应该在这里发布错误信息。 'angular.module('myApp.components')'和'ApiServices'之间没有任何关系,那么指令'abc'将如何知道 – Meeran0823

+0

'ApiServices'。检查其他服务如何写入。 – Meeran0823