Wednesday, October 11, 2017

Click on a value in an array of objects returns the value of another key AngularJS

I have an array of objects iterated over in a list. If I click on the name, it should alert me with the value of the city the name corresponds to.

<div ng-app='myApp'>
    <div ng-controller="AppController">
      <div ng-click="getCity()" ng-repeat="step in steps">
        <p> </p> 
    </div>
</div>

var myApp = angular.module('myApp', []);
myApp.controller('AppController', function ($scope) {
    $scope.steps = [
        {name: "ABC", status: true, city: "Boston"},
        {name: "DEF", status: true, city: "New York"},
        {name: "GHI", status: true, city: "LA"}
];

        $scope.getCity = function(a) {

    }
});

Detailed code here.

–> So I click on “ABC” and “Boston” should be shown to me.

Appreciate the help. Thanks.

Source: AngularJS



from Angular Questions https://angularquestions.com/2017/10/11/click-on-a-value-in-an-array-of-objects-returns-the-value-of-another-key-angularjs/
via @lzomedia #developer #freelance #web #lzomedia.com

No comments:

Post a Comment