如何使用angular在select选项中按每个国家/地区名称插入标记

时间:2016-11-24 10:18:46

标签: angularjs

我看到很多答案,但没有人为我工作。

答案我发现:

选项1:

<select class="form-control" name="country" ng-model="user.country">
            <option value="">choose country</option>
<option ng-repeat="item in countries" value="{{item.name}}" ng-style="background:url('../images/flage/+item.name+.png')>{{item.name}}</option>
        </select>

选项2:

<select class="form-control" name="country" ng-model="user.country">
            <option value="">choose country</option>
<option ng-repeat="item in countries" value="{{item.name}}" ng-style="background:url('../images/flage/+{{item.name}}+.png')>{{item.name}}</option>
        </select>

选项3:

<select class="form-control" name="country" ng-model="user.country">
            <option value="">choose country</option>
<option ng-repeat="item in countries" value="{{item.name}}" data-image="('../images/flage/item.name.png')">{{item.name}}</option>
        </select>

选项4:

<select class="form-control" name="country" ng-model="user.country">
            <option value="">choose country</option>
<option ng-repeat="item in countries" value="{{item.name}}" data-image="('../images/flage/{{item.name}}.png')">{{item.name}}</option>
        </select>

有人知道怎么做吗?

1 个答案:

答案 0 :(得分:-1)

试试这个,

&#13;
&#13;
table1
&#13;
var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
  $scope.name = 'World';
  
  $scope.countries = [
    {
      'name':'india',
      'flag':'http://pngimg.com/upload/flags_PNG14694.png'
    },
        {
      'name':'USA',
      'flag':'https://www.google.com/images/srpr/logo4w.png'
    }
    ]
  
});
&#13;
&#13;
&#13;