Angularjs ng repeat不是从数组中获取值

Angularjs ng repeat不是从数组中获取值,angularjs,angularjs-ng-repeat,Angularjs,Angularjs Ng Repeat,在select下拉列表中使用ng repeat从数组中获取值时遇到问题。作为AngularJS的新手,我确信我在以下代码中犯了一个错误: <select ng-model="selectedItem"> <option ng-repeat="item in sampleArray" value="{{item['Product Description']}}">{{item['Product Description']}}</option> </

在select下拉列表中使用
ng repeat
从数组中获取值时遇到问题。作为AngularJS的新手,我确信我在以下代码中犯了一个错误:

<select ng-model="selectedItem">
    <option ng-repeat="item in sampleArray" value="{{item['Product Description']}}">{{item['Product Description']}}</option>
</select>

欢迎提出任何建议。

请使用以下代码:

<!DOCTYPE html>
    <html>

    <head>
    <script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
    </head>

    <body>

    <div data-ng-app="" data-ng-init="names=[{'Vanilla Product Code':'a1','Product Description':'b1'},{'Vanilla Product Code':'a2','Product Description':'b2'}]">
      <select ng-model="selectedItem">
        <option ng-repeat="item in names" value="{{item['Product Description']}}">{{item['Product Description']}}</option>
    </select>
    </div>

    </body>
    </html>

{{item['productdescription']}

请使用此代码:

<!DOCTYPE html>
    <html>

    <head>
    <script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
    </head>

    <body>

    <div data-ng-app="" data-ng-init="names=[{'Vanilla Product Code':'a1','Product Description':'b1'},{'Vanilla Product Code':'a2','Product Description':'b2'}]">
      <select ng-model="selectedItem">
        <option ng-repeat="item in names" value="{{item['Product Description']}}">{{item['Product Description']}}</option>
    </select>
    </div>

    </body>
    </html>

{{item['productdescription']}

请使用此代码:

<!DOCTYPE html>
    <html>

    <head>
    <script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
    </head>

    <body>

    <div data-ng-app="" data-ng-init="names=[{'Vanilla Product Code':'a1','Product Description':'b1'},{'Vanilla Product Code':'a2','Product Description':'b2'}]">
      <select ng-model="selectedItem">
        <option ng-repeat="item in names" value="{{item['Product Description']}}">{{item['Product Description']}}</option>
    </select>
    </div>

    </body>
    </html>

{{item['productdescription']}

请使用此代码:

<!DOCTYPE html>
    <html>

    <head>
    <script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
    </head>

    <body>

    <div data-ng-app="" data-ng-init="names=[{'Vanilla Product Code':'a1','Product Description':'b1'},{'Vanilla Product Code':'a2','Product Description':'b2'}]">
      <select ng-model="selectedItem">
        <option ng-repeat="item in names" value="{{item['Product Description']}}">{{item['Product Description']}}</option>
    </select>
    </div>

    </body>
    </html>

{{item['productdescription']}
这工作正常

我认为您没有使用
$scope
引用
sampleArray

JSFIDLE是否正常工作

我认为您没有使用
$scope
引用
sampleArray

JSFIDLE是否正常工作

我认为您没有使用
$scope
引用
sampleArray

JSFIDLE是否正常工作

我认为您没有使用
$scope
引用
sampleArray


是JSFIDLE

您应该使用ng选项

<select ng-model="selectedItem" ng-options="it['Vanilla Product Code'] as it['Product Description'] for it in sampleArray">
</select>


请参阅演示:

您应该使用ng选项

<select ng-model="selectedItem" ng-options="it['Vanilla Product Code'] as it['Product Description'] for it in sampleArray">
</select>


请参阅演示:

您应该使用ng选项

<select ng-model="selectedItem" ng-options="it['Vanilla Product Code'] as it['Product Description'] for it in sampleArray">
</select>


请参阅演示:

您应该使用ng选项

<select ng-model="selectedItem" ng-options="it['Vanilla Product Code'] as it['Product Description'] for it in sampleArray">
</select>


请参阅演示:

谢谢您的回答:)。。但我正在寻找从控制器端传递的数组。谢谢您的回答:)。。但我正在寻找从控制器端传递的数组。谢谢您的回答:)。。但我正在寻找从控制器端传递的数组。谢谢您的回答:)。。但是我一直在寻找从控制器端传递的数组。谢谢你的回答。关于$scope的引用你是正确的!!谢谢你的回答。你对$scope的引用是正确的!!谢谢你的回答。你对$scope的引用是正确的!!谢谢你的回答。你对$scope的引用是正确的!!谢谢您的回答…:)但是演示中的下拉列表也没有显示值。是否为我显示:。我以为你想要标签的描述。如果没有,调整ng选项的定义,应该非常清晰。再次感谢您的评论!!谢谢您的回答…:)但是演示中的下拉列表也没有显示值。是否为我显示:。我以为你想要标签的描述。如果没有,调整ng选项的定义,应该非常清晰。再次感谢您的评论!!谢谢您的回答…:)但是演示中的下拉列表也没有显示值。是否为我显示:。我以为你想要标签的描述。如果没有,调整ng选项的定义,应该非常清晰。再次感谢您的评论!!谢谢您的回答…:)但是演示中的下拉列表也没有显示值。是否为我显示:。我以为你想要标签的描述。如果没有,调整ng选项的定义,应该非常清晰。再次感谢您的评论!!下投者,请考虑在投票前添加评论!!!!下投者,请考虑在投票前添加评论!!!!下投者,请考虑在投票前添加评论!!!!下投者,请考虑在投票前添加评论!!!!