ng-hide不使用ng-model

时间:2014-06-10 23:05:17

标签: angular-ngmodel ng-hide

我想从下拉列表中显示/隐藏特定选项选择的div。 但是div一直都是隐藏的。

 <select class="form-control" ng-model="Type">
                    <option>First</option>
                    <option>Second</option>
                    <option>Third</option>
                    <option>Forth</option>
                </select>

      <div ng-hide="Type==='First'">
      <label>Div Content</div>
      </div>

1 个答案:

答案 0 :(得分:0)

为此目的更好的ng-switch指令适合。 请参阅jsfiddle here

HTML:

<div ng-app="app">
    <div ng-controller="Ctrl">
        <select ng-model="selection" ng-options="item for item in items"></select>
        <hr/>
        <div class="animate-switch-container" ng-switch on="selection">
            <div ng-switch-when="first">First option</div>
            <div ng-switch-when="second">Second option</div>
            <div ng-switch-when="third">Third option</div>
            <div ng-switch-when="forth">Forth option</div>
            <div ng-switch-default>default</div>
        </div>
    </div>
</div>

JS:

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

app.controller('Ctrl', function ($scope) {
    $scope.items = ['first', 'second', 'third', 'forth'];

});