Mohan Gopi Mohan Gopi - 1 year ago 71
AngularJS Question

how to view the data from server using $http.get

i have an empty array called

$scope.mobileBrandArray= [];

now i am trying to get the data from my server using $http.get inside the function

here is my app.js code

app.controller('myCtrl' , function($scope , $http){
$scope.mobileBrandArray = [];
$scope.getMobileBrandArray = function(){
.success(function(response) {
.error(function(response) {
alert("error ");

here i am not able to view my data in the UI, but i try
function without the
it works fine but i need my array outsid the

here is my html code

<tr ng-repeat="mobileBrand in mobileBrandArray" ng-include="getTemplate(mobileBrand)">
<script type="text/ng-template" id="display">
<button type="button" class="btn btn-primary" ng-click="editMobileData(mobileBrand)">Edit</button>
<button type="button" class="btn btn-danger" ng-click="deleteMobileData(mobileBrand)">Delete</button>
<script type="text/ng-template" id="edit">
<td><input type="text" ng-model=mobileBrand.brandCode class="form-control input-sm"/></td>
<td><input type="text" ng-model=mobileBrand.brandName class="form-control input-sm"/></td>
<td><input type="text" ng-model=mobileBrand.brandStatus class="form-control input-sm"/></td>
<td><input type="text" ng-model=mobileBrand.brandCreatedOn class="form-control input-sm"/></td>
<button type="button" class="btn btn-primary" ng-click="updateMobileData(mobileBrand)">Save</button>
<button type="button" class="btn btn-danger" ng-click="reset()">Cancel</button>

Answer Source

I don't see where you call the getMobileBrandArray() function. You have two options you could:

add ng-init='getMobileBrandArray()' to the top of your table to automatically run the $http.get function.

or add ng-click='getMobileBrandArray()' to a button you want to initiate the get function.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download