angularjs - Dynamically selecting dropdown, in relation to url? -


currently i'm trying figure out way preselect drop down option depending on parameters in url. ie: www.example.com/#/two, if hit url have 2 in 'items' scope preselected 'selecteditem' scope. right below code default 'one' in 'items' scope. i've tried parsing url , injecting 'selecteditem' scope didn't work either.

<select ng-model="selecteditem"          ng-options="item item.name item in items"> </select>  var testurl = 'http://www.example.com/#/two';  $scope.items = [   {name:'one', value:'check1'},   {name:'two', value:'check2'} ];  $scope.selecteditem = $scope.items[1]; 

fiddle convenience: sandbox

i use $timeout method make sure timing correct , loop through items , find correct one. like:

$timeout(function () {     var page = testurl.substr(testurl.length - 3);     (var = 0; < $scope.items.length; i++) {         if ($scope.items[i].name === page) {             $scope.selecteditem = $scope.items[i];         }     } }); 

updated fiddle.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -