角度选择与图像

Fra*_*ssi 2 javascript select angularjs ionic-framework

情况:

我需要在语言选择中插入标志.我在谷歌和StackOverflow上搜索过但是创建的解决方案对我不起作用.

代码:

在控制器中:

 $scope.language_list = [{'name': 'english', 'url': 'https://raw.githubusercontent.com/stevenrskelton/flag-icon/master/png/16/country-4x3/gb.png'},{'name': 'italian', 'url': 'https://raw.githubusercontent.com/stevenrskelton/flag-icon/master/png/16/country-4x3/it.png'}];
Run Code Online (Sandbox Code Playgroud)

在视图中:

<select ng-model="language_selected">
    <option ng-repeat="language in language_list" data-image="{{language.url}}" >{{language.name}}</option>
</select>
Run Code Online (Sandbox Code Playgroud)

例:

http://jsfiddle.net/tcVhN/168/

问题:

如何在角度选择内插入图像?

编辑:

这是解决方案的Plunker,清理了:

http://plnkr.co/edit/hMlNjkDL3l0QKF37pCa0?p=preview

K.T*_*ess 10

作为其他答案,您不能使用它<options>来添加图像,但您可以使用角度模块ui-select来实现您想要做的事情.

这是一个带有ui-select的数据演示.

清理代码并获得所需内容.

如果您对搜索框不感兴趣,请将CSS覆盖为,

 .select2-search {
      display: none;
 }
Run Code Online (Sandbox Code Playgroud)

DEMO


MoL*_*Low 5

this is impossible with a native select element,

therfore, you need to design a selectbox using other html elements & css,

try this out:

var app = angular.module('app',[]);

//app.directive('appDirective', function() {});
//app.factory('appService', function() {});

function AppCtrl($scope) {
	$scope.obj={language_selected : {'name':'Choose a language'}};
    $scope.language_list = [{'name': 'english', 'url': 'https://raw.githubusercontent.com/stevenrskelton/flag-icon/master/png/16/country-4x3/gb.png'},{'name': 'italian', 'url': 'https://raw.githubusercontent.com/stevenrskelton/flag-icon/master/png/16/country-4x3/it.png'}];
    
}
Run Code Online (Sandbox Code Playgroud)
.select_list{
    background-color: #fff;
    border: 1px solid #b3b3b3;
    cursor: pointer;
    height: 21px;
    line-height: 21px;
    padding: 3px 5px;
    position: relative;
    vertical-align: middle;
    width: 250px;
}
.select_list:after{
    content:"?";
    position:absolute;
    right:3px;
    color:#b3b3b3;
}
.select_list > .options{
    display:none;
    position:absolute;
    top:100%;
    left:-1px;
    width:100%;
    border:1px solid #666;
    padding:0;
    margin:0;
}

.select_list.active > .options{
    display:block;
}

.select_list > span, .select_list > .options li {
    background-position: 5px center;
    background-repeat: no-repeat;
    padding-left: 30px;
    list-style:none;
}

.select_list > .options li:hover {
    background-color:#eee;
}
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js"></script>
<div ng-app="app"  ng-controller="AppCtrl">
<div class="select_list" ng-class='{active:active}' ng-click="active=!active">
    <span ng-style="{'background-image':'url('+obj.language_selected.url+')'}">{{obj.language_selected.name}}</span>
    <ul class="options">
        <li class="select_list_option" ng-repeat="language in language_list" ng-click="obj.language_selected=language" ng-style="{'background-image':'url('+language.url+')'}">{{language.name}}</li>
        </ul>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)