首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >请重复选择列表中的初始值

请重复选择列表中的初始值
EN

Stack Overflow用户
提问于 2016-11-05 11:40:13
回答 1查看 60关注 0票数 2

请帮我重复一遍。我使用ng-​​创建了一个值列表。如何指定我想要首先显示的列表中间的值(我想在列表中第一个显示“地球”)?我的代码:

html

代码语言:javascript
复制
<li class="list__item" ng-repeat="poster in posters">{{poster.title}}</li>

主计长:

代码语言:javascript
复制
'use strict';
 angular.module('oldmenTest')
  .controller('FormController', ['$scope', 'postersName', function($scope, postersName) {
  $scope.posters= postersName.getPosters();

}]);

vars:

代码语言:javascript
复制
'use strict';

angular.module('oldmenTest')
.service('postersName', function() {

var posters = [{
    title: 'Mars',
    description: 'NASA\'s Mars Exploration Program seeks to understand whether Mars was, is, or can be a habitable world. Mission like Mars Pathfinder, Mars Exploration Rovers, Mars Science Laboratory and Mars Reconnaissance Orbiter, among many others, have provided important information in understanding of the habitability of Mars. This poster imagines a future day when we have achieved our vision of human exploration of Mars and takes a nostalgic look back at the great imagined milestones of Mars exploration that will someday be celebrated as “historic sites.”',
    image: '/images/mars.jpg'
}, {
    title: 'Earth',
    description: 'There\'s no place like home. Warm, wet and with an atmosphere that\'s just right, Earth is the only place we know of with life – and lots of it. JPL\'s Earth science missions monitor our home planet and how it\'s changing so it can continue to provide a safe haven as we reach deeper into the cosmos.',
    image: '/images/earth.jpg'
}
];

this.getPosters = function(){
    return posters;
};

});

谢谢你帮忙!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-05 12:15:43

这只是解决办法,但它会起作用的..

代码语言:javascript
复制
angular.module('app', [])
      .controller('Controller', function($scope) {
       
$scope.posters = [{
    title: 'Mars',
    description: 'NASA\'s Mars Exploration Program seeks to understand whether Mars was, is, or can be a habitable world. Mission like Mars Pathfinder, Mars Exploration Rovers, Mars Science Laboratory and Mars Reconnaissance Orbiter, among many others, have provided important information in understanding of the habitability of Mars. This poster imagines a future day when we have achieved our vision of human exploration of Mars and takes a nostalgic look back at the great imagined milestones of Mars exploration that will someday be celebrated as “historic sites.”',
    image: '/images/mars.jpg'
}, {
    title: 'Earth',
    description: 'There\'s no place like home. Warm, wet and with an atmosphere that\'s just right, Earth is the only place we know of with life – and lots of it. JPL\'s Earth science missions monitor our home planet and how it\'s changing so it can continue to provide a safe haven as we reach deeper into the cosmos.',
    image: '/images/earth.jpg'
}, {
    title: 'Jupiter',
    description: 'There\'s no place like home. Warm, wet and with an atmosphere that\'s just right, Earth is the only place we know of with life – and lots of it. JPL\'s Earth science missions monitor our home planet and how it\'s changing so it can continue to provide a safe haven as we reach deeper into the cosmos.',
    image: '/images/jupiter.jpg'
}
];
      })
代码语言:javascript
复制
<!DOCTYPE html>

<head>
  <script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0/angular.min.js"></script>
  <script src="script.js"></script>
</head>

<body ng-app="app">
  <div ng-controller="Controller">
    <li class="list__item" ng-if="poster.title=='Earth'" ng-repeat="poster in posters">{{poster.title}}</li>
    <li class="list__item"  ng-if="poster.title!='Earth'" ng-repeat="poster in posters">{{poster.title}}</li>
  </div>
</body>

</html>

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40437809

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档