android - Setting certain item in select option from object collection using ionic framework -


short description of problem:

i facing 2 problems while using "select" in ionic working when tried using angularjs. 1. setting array of 1st index select coming blank. 2. trying update array splicing , trying update select again bringing me blank select option.

what behavior expecting?

2 problems expecting respective array item selected given through controller.

steps reproduce:

  1. at start when u run app blank select option.
  2. the other problem can seen deleting item , other default item selected.

code snippet:

            .controller('dashctrl', function($scope) {              $scope.options = [{name: 'var1',id: 1}, { name: 'var2', id: 2}, {name: 'var3',id: 3}];             $scope.yourselect = $scope.options[0];              $scope.delete = function() {               //  alert("clciked");               $scope.deleted = $scope.options.splice(1,1);               $scope.yourselect = $scope.options[0];                 alert( $scope.yourselect.name);             }              $scope.changed = function(yourselect) {                 alert( $scope.yourselect.name);               }             }) 

for ionic 1 issues:

http://plnkr.co/edit/zridlmql8vprdk1nndna?p=preview

ionic info :

cordova cli: 6.0.0 ionic version: 1.3.1 ionic cli version: 1.7.14 ionic app lib version: 0.7.0 os: windows 7 sp1 node version: v5.6.0

here working solution - http://plnkr.co/edit/qodvoqnhsdtr7laglbvv?p=preview

re: @ start when u run app blank select option. because of ng-init not been set correctly. instead of

ng-init="yourselect='var1'"  

you should have just:

ng-init="yourselect" 

the reason why selected option should object, 1 of those, declared ng-options, , not string value. when select option, angular give reference selected object, not selected "value".

re: other problem can seen deleting item , other default item selected. check in controller.js file how update model in $scope.changed() , how selected deletion option removed $scope.options array.


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -