javascript - AngularJS ngHide and ngShow depending on <select> option -
i'm trying change view depending on option select in tag, using nghide/ngshow, can't seem figure out how make work.
this current idea:
<header class="hero-unit" id="banner" ng-include="'components/header/header.html'"></header> <div ng-include="'components/navbar/navbar.html'"></div> <div class="container"> <h3 class="site-headline">opret nyt produkt</h3> <hr> <form> <div class="container jumbotron"> <div class="col-md-12"> <select> <option ng-repeat="option in options" name="chosenoption"> {{ option.name }} </option> </select> </div> <div ng-show="{{ option.name }} == 'pool'" ng-include="'new-pool.html'"></div> </div> </form> </div> <footer class="footer" ng-include="'components/footer/footer.html'"></footer> bu can't seem access {{ option }}, makes sense since i'm out of ng-repeat scope.
i tried making method:
$scope.setproduct = function(productname){ $scope.product = productname; console.log($scope.product); }; and call ng-change on select tag, set product.name = chosenoption. print out correct $scope.product doesn't show ng-include.
i can't seem wrap head around it, , use helping hand.
you need add ng-model <select>:
<div class="container jumbotron"> <div class="col-md-12"> <select ng-model="selectedoption"> <option ng-repeat="option in options" name="chosenoption"> {{ option.name }} </option> </select> </div> <div ng-show="selectedoption.name == 'pool'" ng-include="'new-pool.html'"></div> </div> the ng-model on select set selected object.
Comments
Post a Comment