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/'
});
}
};
})();
ca n u提供一些模拟数据的response.data –
abc指令在你的html? – Max
请提供ApiServices代码 – madhur