DWQA QuestionsCategory: ProgramHow can angularjs ng repeat the data in the array to the corresponding position of HTML?
Elvis_ Euro asked 3 weeks ago

How can I make the image path in the banner URL array replace the IMG path with ng repeat to HTML?
Because of the limitation of CSS, repeat Li label is used to implement multiple image rotation. But now I don’t know how to go to repeat

  • Replace the image path when labeling. Please give me some guidance.HTML:
    <li ng-repeat="x in text">
    <img>
    </li>
    

    The array is as follows:

    [{
    "id": "01",
    "imgurl": "images/banner_01.jpg",
     "bannerurl":[{
          "bannerimgurl0": "images/banner_04.jpg",
          "bannerimgurl1": "images/banner_04.jpg",
          "bannerimgurl2": "images/banner_04.jpg",
          "detailsimgurl": "images/banner_05.jpg"
        }],
    "Title": "safety chair",
    "quantity": "10",
    "cost": "896",
    "status": "0"
    }]
  • 1 Answers
    Best Answer
    Yu an answered 3 weeks ago

    Although I don’t quite understand what you mean, I guess it’s like this:
    JS, in controller

    function bannerController($scope){
        $scope.banner = [{
        "id": "01",
        "imgurl": "images/banner_01.jpg",
         "bannerurl":[{
              "bannerimgurl0": "images/banner_04.jpg",
              "bannerimgurl1": "images/banner_04.jpg",
              "bannerimgurl2": "images/banner_04.jpg",
              "detailsimgurl": "images/banner_05.jpg"
            }],
        "Title": "safety chair",
        "quantity": "10",
        "cost": "896",
        "status": "0"
        }]
    }

    Under the corresponding controller in HTML

    <div ng-controller="bannerController">
        <ul ng-repeat="(name,url) in banner[0].bannerurl[0]">
            <li>
                <img src="{{url}}">
            </li>
        <ul>
    </div>
    

    Look at the document. This part is very basic. I hope it is the effect you want.

    Yu an replied 3 weeks ago

    The traversal is not the banner URL array, but the key = > value of the first obj in the bannerurl array (i.e. name = “bannerimgurl0”, url = “images / bannerur [04. JPG” and so on). If you want to implement the whole banner and the bannerurl array under each banner, you need to nest two layers of NG repeat, and put the ID filter next to the outermost ng repeat.

    Yu an replied 3 weeks ago

    I’ve been hanging out on SF recently. If you have any questions, you can send me a personal message. Please remember to like it and accept it.