Angular script examples

ng-options
<html>
<head>
<script src=""//ajax.googleapis.com/ajax/libs/angularjs/1.2.12/angular.min.js""></script>
<script><!-- Angular script--></script>
</head>
<body ng-app=""app"" ng-controller=""Ctrl"">
    <!--model1.value is bound to ng-option selected value-->
    <select ng-model=""model1.value"" ng-options=""s.value as s.text for s in models""></select>
    value={{model1.value}} <!--value=2-->
    <select ng-model=""model2"" ng-options=""s.text for s in models""></select>
    text={{model2.text}} value={{model2.value}} <!--text=value1 value=1-->
</body>
</html>
var app = angular.module("app",[]);
app.controller('Ctrl', ["$scope",($scope) =>{
    $scope.model1={value:2};
    $scope.models=[{value:1,text:'value1'},{value:2,text:'value2'}];
    $scope.model2=$scope.models[0];
}]);

Leave a Reply

Your email address will not be published. Required fields are marked *