bruh bruh - 25 days ago 5x
AngularJS Question

Angular select and ng-model

I'm trying to populate a select field with content from an array. I'm confused as to what exactly my "model" is.

I'm looking to access content from

which is an array of objects. I assume this is my "model".


<select ng-model="ctrl.contents"
ng-options=" in as content in contents">


var ctrl = this
from ViewPage.controller.js

If I was to
from ViewPage.controller.js the array of objects would be returned:

> 0: ContentViewModel
> title: Object // Each numbered array object has similar contents
name: "Thomas"
> 1: ContentViewModel
> 2: ContentViewModel
> 3: ContentViewModel

I can't seem to get the select field populated with anything. Am I getting the ng-model wrong?


Your 'model' is a separate variable that will contain the selected value of your select menu - set it to something like ctrl.selectedItem.

Your ng-options parameters should look like this:

ng-options=" for content in ctrl.contents"

For more info, refer to this example - checkout both the html and js in app.js.