显示数组中的对象取决于stateParam

时间:2019-11-04 14:26:29

标签: angularjs angular-ui-router

我有一个数组,我想在页面上显示指向/ id的那个数组。例如,我有一个链接product.com/1,我想显示一个具有此ID的数组中的对象

数组

  .controller('controller', function (
    $scope, $stateParams
  ) {
    $scope.array = [
      {
        text: 'Some text',
        logoUrl: 'some url',
        backgroundUrl: 'some url',
        id: '1'
      },
      {
        text: 'Some text',
        logoUrl: 'some url',
        backgroundUrl: 'some url',
        id: '2'
      },
      {
        text: 'Some text',
        logoUrl: 'some url',
        backgroundUrl: 'some url',
        id: '3'
      },
      {
        text: 'Some text',
        logoUrl: 'some url',
        backgroundUrl: 'some url',
        id: '4'
      },
    ]
  });

状态

.state('app.state', {
          url: '/:id',
          params: {
            id: null
          },
          views: {
            'main@app': {
              controller: 'controller',
              templateUrl: 'views/app/index.html'
            },
          }

        })

html

<img src="{{array[({{array.id}})].backgroundUrl}}" />
                <img src="{{array[{{array.id}}].logoUrl}}" />
              </div>
              <div class="pm-goodies-card-text">
                <p>{{array[{{array.id}}].text}}</p>

我了解代码并非正常工作,但是任何人都可以给我一个如何使其工作的想法吗? (对不起,我的英语)

0 个答案:

没有答案