如果搜索字段具有值,则为addclass:Angularjs

Erm*_*bel 3 javascript css select angularjs angularjs-ng-class

我有一个搜索输入字段和一个列表框,

    <input type="text"  class="inputSearch" placeholder="Search" ng-model="searchRoleOne"/>
    <i class="fa fa-search"></i>                                                         
    <select multiple class="listMutiple top5" ng-model="selectedRoleValue">
        <option ng-selected="selectrole" ng-repeat="role in roles | filter:searchRoleOne" value="{{role}}">{{role}}</option>      
    </select>
Run Code Online (Sandbox Code Playgroud)

我需要addclass说

    .addClear{
        background: url(../images/Close.png) no-repeat right -10px center;
        background-repeat: no-repeat;
        background-position: right 5px center;
    }
Run Code Online (Sandbox Code Playgroud)

只要有文字,我就应该在改变功能上发生.点击.addClear类搜索字段应该为空,ng模型也是如此.

我怎样才能做到这一点?

我尝试ng-class="{'addClear': searchRoleOne}"在搜索字段中使用.它工作不正常.

Pan*_*kar 5

只需你可以试试这个

在这里小提琴

ng-class="{'addClear': searchRoleOne.length > 0}"
Run Code Online (Sandbox Code Playgroud)

希望这可以帮到你