Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJs: Select Value From DropDown

I am using AngularJS with JQM I create a drop-down for selecting value and data comies in it using AngularJS Controller. It works fine But when I add data-native-menu="false in <select> then strange executions I select first value it selected second.

My HTML Part

<div ng-controller="MyCtrl">
    <select data-native-menu="false" data-role="listview" ng-options="size as size.name for size in sizes " ng-model="item" ng-change="update()"></select>
     {{item.code}} {{item.name}}
</div>

JS Part

myApp.controller('MyCtrl',function($scope){
    $scope.sizes = [ {code: 1, name: 'n1'}, {code: 2, name: 'n2'}];
    $scope.update = function() {
    console.log($scope.item.code, $scope.item.name)
}});

If I remove data-native-menu="false" data-role="listview" then code works fine

Please Help Me

Demo Page of My Example is Here

like image 242
Blu Avatar asked Dec 26 '22 20:12

Blu


1 Answers

You can find working code in Fiddle

html

<div ng-controller = "fessCntrl" > 
 <div query-mobile-tpl>
  <select data-role="listview" data-inset="true" ng-options="size as size.name for size in sizes " ng-model="item" x-ng-change="update(item)"></select>
  <pre> {{item.code | json}} {{item.name | json}}</pre>
  </div>
</div>

controller

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

fessmodule.controller('fessCntrl', function ($scope) {

    $scope.sizes = [ {code: 1, name: 'n1'}, {code: 2, name: 'n2'}];
    $scope.update = function() {
    console.log($scope.item.code, $scope.item.name)
    };
});


fessmodule.directive('jqueryMobileTpl', function() {
  return {
    link: function(scope, elm, attr) {
      elm.trigger('create');
    }
  };
});

fessmodule.directive('repeatDone', function () {
    return function (scope, element, attrs) {
        // When the last element is rendered
        if (scope.$last) { 
            element.parent().parent().trigger('create');
        }
    }
});

fessmodule.$inject = ['$scope'];

Sounds like you use old angular sources or get collisions with other sources.

Hope it will help you

like image 146
Maxim Shoustin Avatar answered Dec 28 '22 09:12

Maxim Shoustin