How, to use a static select in angularjs.
I wanna create a select ng-model with change event with statc values.
<form ng-controller="mycontroller">
    <select class="form-control"  name='modelid' ng-model="modelid"  ng-change="modelidchange">
        <option value="-1">select </option>       
        <option value='4'>Static text 4</option>
        <option value='1'>Static text 1</option>
        <option value='2'>Static text 2</option>                 
    </select>
</form>
my controller:
angular.module('app').controller('chapter',function($scope,$http) {
    console.log('ok')
    $scope.id = modelid
    alert($scope.id)
});
I just wanna get de model value, but this error:
Error: ngOptions:iexp
Invalid Expression
I DON'T WANNA USE NG-OPTIONS just a static select.
Can somebody help me ?
check this jsfiddle link, maybe it will help
<select ng-model="filterCondition.operator">
    <option ng-selected="{{operator.value == filterCondition.operator}}" ng-repeat="operator in operators" value="{{operator.value}}">{{operator.displayName}}</option>
and this answer
You first need to change your AngularJS Code a little bit...
From this
angular.module('app').controller('chapter',function($scope,$http){
                   console.log('ok')
    $scope.id = modelid
    alert($scope.id)
});
To this
angular.module('app').controller('chapter',function($scope,$http){
    $scope.id = $scope.modelid;
    alert($scope.id);
});
Next your Controller doesn't match... In HTML your Controller is
<form ng-controller="mycontroller">
In Angular your Controller is
.controller('chapter'...
So change it from this
<form ng-controller="mycontroller">
to this
<form ng-controller="chapter">
And last but not least :-)
You need to define the function you want to call with ng-change in your controller... So change the whole code to the following...
HTML
<form ng-controller="chapter">
    <select class="form-control"  name='modelid' ng-model="modelid"  ng-change="modelidchange()">
    <option value="-1">select </option>       
    <option value='4'>Static text 4</option>
    <option value='1'>Static text 1</option>
    <option value='2'>Static text 2</option>
</select>
Angular
angular.module('app').controller('chapter',function($scope,$http){
    $scope.modelidchange = function () {
        $scope.id = $scope.modelid;
        alert($scope.id)
    }
});
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With