Array key value get in html from controller in angular js?

Martin

I am getting array of key in angular js controller. And I am able to get particular value in controller. But I am not able to get in view(HTML).

Controller:

var statusLength= res.fsus.length;  
for(var i=0; i<statusLength; i++)
{    
       $scope.opts=res.fsus[i].statusMessageType.MasterConsignment.ReportedStatus.ReasonCode

}

In this loop I am able to get particular value. I want to display these value in View(HTML) part. I am new in angular js. I am not sure I am doing right or not.

Value is In Loop

var
car
ban

But when I tried to get in UI(HTML) then It will displaying only v a r. Not displaying var car ban. It is displaying only v a r

HTML

<li ng-repeat=" opt in opts">
       <span class="step">{{opt}}</span> 
</li>

JSON

fsus[{
  statusMessageType:{
       MasterConsignment:{
           ReportedStatus:{
             ReasonCode:"var"
             }
           }
       },
    statusMessageType:{
       MasterConsignment:{
           ReportedStatus:{
             ReasonCode:"car"
             }
           }
       },
   statusMessageType:{
       MasterConsignment:{
           ReportedStatus:{
             ReasonCode:"ban"
             }
           }
       },
}]

please share your idea. thanks

Sajeetharan

First of all your JSON is not a valid one, change it as,

[ { "statusMessageType": { "MasterConsignment": { "ReportedStatus": { "ReasonCode": "var" } } } }, { "statusMessageType": { "MasterConsignment": { "ReportedStatus": { "ReasonCode": "car" } } } }, { "statusMessageType": { "MasterConsignment": { "ReportedStatus": { "ReasonCode": "ban" } } } } ]

You can use ng-repeat with track by $index to display the options

<li ng-repeat="test in res.fsus track by $index">
      <span class="step">    {{test.statusMessageType.MasterConsignment.ReportedStatus.ReasonCode}}
      </span> 
</li>

DEMO

var app = angular.module('testApp',[]);
app.controller('testCtrl',function($scope){
   $scope.res ={};
   $scope.res.fsus = [
  {
    "statusMessageType": {
      "MasterConsignment": {
        "ReportedStatus": {
          "ReasonCode": "var"
        }
      }
    }
  },
  {
    "statusMessageType": {
      "MasterConsignment": {
        "ReportedStatus": {
          "ReasonCode": "car"
        }
      }
    }
  },
  {
    "statusMessageType": {
      "MasterConsignment": {
        "ReportedStatus": {
          "ReasonCode": "ban"
        }
      }
    }
  }
];
 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="testApp" ng-controller="testCtrl">
<li ng-repeat="test in res.fsus track by $index">
  <span class="step">    {{test.statusMessageType.MasterConsignment.ReportedStatus.ReasonCode}}
  </span> 
</li>
</body>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Angular 2 get key and value from json array with dynamic key

From Dev

Get JSON value from key value array with Angular

From Dev

Angular JS not getting scope value from HTML to controller

From Dev

angular js: Not able to pass value from controller to html of an included page

From Dev

How to get an Key value pair from a array of objects in angular

From Dev

Get key value from a HTML attribute array javascript

From Dev

Underscore.js Get key from value in array

From Dev

How to get route value to controller in angular js

From Dev

Get Value from Key Value array

From Dev

Pass array variable from controller to html in Angular

From Dev

Angular js Controller method from HTML with a parameter

From Dev

angular js autocomplete key value array

From Dev

Unable to get value from html to controller

From Dev

How to get the select value from the html to controller

From Dev

How to get the object key and value into an array in JS?

From Dev

Groovy: Get value with key from a string array

From Dev

Get value by key from array javascript

From Dev

how to get single value from array by key

From Dev

PHP get key value from array

From Dev

Can not get key:value from Json array

From Dev

php get value of array from key name

From Dev

Get the key value from multivalued array in php

From Dev

Get the value of the Key from a Json Array

From Dev

get key with specific value from multidimention array

From Dev

Get value from key in an array in PHP

From Dev

PHP array cannot get value from key

From Dev

How to get the value from a JSON key in JS?

From Dev

JS - How to get value from object by key

From Dev

get key value from php array with string as key

Related Related

HotTag

Archive