angularjshtmljquery-select2ui-select

How to get value in angularjs object attribute


How can I get the value of field.jobtype in a controller?

var app=angular.module('myapp',['ui.bootstrap','ui.select']);
app.controller('mycontroller',function($scope){
    $scope.onStateSelected = function (selectedItem) {
        $scope.selectedState=selectedItem.name;
    }
    $scope.oncarearchange=function(item){
        $scope.selectedLocation=item.name;
    }
    var state=[{"name":"entry"},{"name":"intermediate"},{"name":"senier"},{"name":"teamlead"}];
    var carearlevel=[{"name":"entry"},{"name":"intermediate"},{"name":"senier"}{"name":"teamlead"}];
    $scope.states=state;
    $scope.carear=carearlevel;
});
<ui-select ng-model="field.jobtype"  theme="select2"  ng-disabled="disabled" class="form-control input-md c-square" on-select="onStateSelected($item)">
  <ui-select-match placeholder="Select a jobtype...">
    {{$select.selected.name}}
  </ui-select-match>
  <ui-select-choices repeat="state.name as state in states | filter: $select.search">
  {{state.name}}
  </ui-select-choices>
</ui-select>

Here the ui-select display values from the array sate which is assigned to $scope.states,but when try to display field, jobtype in controller it shows the error jobtype is not defined.


Solution

  • Its working when i used $scope.field. ------ in my angularjs controller