cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

fill select widget with for loop

GianVal
15-Moonstone

fill select widget with for loop

I want to fill the 

$scope.view.wdg["select-1"].list

with a for loop.

just like i can do with the following method. 

var title = []; for(var i = 0; i < array.length; i++) { title[i] = { name: array[i], value: i+1 }; }

 

How can I do?

ACCEPTED SOLUTION

Accepted Solutions

both approaches are working and your code show work - not sure what is not working for you 

 

$scope.colors = function () {

        var listOfColors = [
              {display: "Red",value: "red"},
              {display: "Green",value: "green"},
              {display: "Blue",value: "blue"}
       ]

        $scope.view.wdg.colorSelector.list = title;
}

$scope.$on("$ionicView.afterEnter", function (event) {
$scope.view.wdg["colorSelector"].list = title;
});

// or 

$scope.$on('modelLoaded', function (evt, arg) {
     $scope.colors();

});

View solution in original post

2 REPLIES 2
sebben
14-Alexandrite
(To:GianVal)

Hi,

you can do it like this:

var array = ["a","b","c"]
var title = []; 
for(var i = 0; i < array.length; i++)
{ title[i] = { display: array[i], value: i+1 }; }
$scope.$on("$ionicView.afterEnter", function (event) {
$scope.view.wdg["select-1"].list = title;
});

both approaches are working and your code show work - not sure what is not working for you 

 

$scope.colors = function () {

        var listOfColors = [
              {display: "Red",value: "red"},
              {display: "Green",value: "green"},
              {display: "Blue",value: "blue"}
       ]

        $scope.view.wdg.colorSelector.list = title;
}

$scope.$on("$ionicView.afterEnter", function (event) {
$scope.view.wdg["colorSelector"].list = title;
});

// or 

$scope.$on('modelLoaded', function (evt, arg) {
     $scope.colors();

});

Announcements

Top Tags