How to show item from json Array one by one in Angular JS

前端 未结 1 1060
长情又很酷
长情又很酷 2021-01-17 02:11

I am developing one prototype application in ionic framework. I am newbie for angular js, HTML, CSS , Java Script and all this stuff.

I have one json file which I am

相关标签:
1条回答
  • 2021-01-17 03:02

    OK, so I'm not 100% sure what you want but I'll take a stab at it. In the future, it would be helpful to post less code (probably not the entire project you are working on). It is a good idea to make a simpler example than the "real" one, where you can learn what you need to learn and then go apply it to the "real" code that you have.

    Anyways, this example is a simple button that you click on to change what is displayed.

    var app = angular.module('MyApplication',[]);
    
    app.controller('MyController', ['$scope', function($scope){
        $scope.indexToShow = 0;
        $scope.items = [
            'item 1', 
            'item 2', 
            'item 3'
        ];
        
        $scope.change = function(){
            $scope.indexToShow = ($scope.indexToShow + 1) % $scope.items.length;
        };
    }]);
    .simple-button {
      cursor: pointer;
    }
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
    <div ng-app="MyApplication" ng-controller="MyController">
      <div ng-repeat="item in items track by $index" ng-show="$index == indexToShow">
        {{item}}
      </div>
      <div class="simple-button" ng-click="change()">click me!</div>
    </div>

    0 讨论(0)
提交回复
热议问题