I searched for this but I did not get any answer as I want, please give me a solution, I want to use ng-init inside ng-repeat, ng-init should give me different response at every loop here is my HTML
<html> <body ng-app="crmApp"> <div ng-controller="customerDetailController"> <div ng-repeat="clientDetail in client"> <p>{{clientDetail.name}}</p> <div ng-init="seoDetails = getCustDetail(clientDetail.name)"> <p>{{seoDetails.cust_Name}}</p> </div> </div> </div> </body> </html>
and my js is
<script> var crmMain = angular.module('crmApp', ['ngRoute','ngMaterial']); crmMain.controller('customerDetailController',function customerDetailController($scope, $http, customerDetailFactory,$window) { $scope.client = []; $scope.init = function () { $scope.getCustomerData(); }; $scope.getCustomerData = function () { customerDetailFactory.getCustomerDetailData().then(function (response) { $scope.client = response.data; }); }; $scope.getCustDetail = function (Name) { var custDetail = []; custDetail = customerDetailFactory.getCustomerDetailData(Name).then(function (response) { alert(response.data.cust_Name); return response.data; }); return custDetail; }; $scope.init(); }); crmMain.factory('customerDetailFactory', ['$http', function ($http) { var factory = {}; var url = 'phpFile/customerDetail.php'; factory.getCustomerDetailData = function (Name) { return $http({ method: 'POST', url: url, data: { 'functionName': 'clientDetailPage', 'customerName': Name } }); }; return factory; }]); </script>
In inside getCustDetail function I was given alert in there it 'll show name, but I don't know why it not showing in HTML.is anything wrong I did?
I have got one solution for this, I think I have to use Promises for this, but I don't know how to use it can anyone help me in this?
alert(response.data.cust_Name);
?ng-init
. docs.angularjs.org/api/ng/directive/ngInit