AngularJS problems with ng-options selected value

喜你入骨 提交于 2019-12-01 22:29:25

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope, $timeout) {
  $scope.name = 'World';
  
  $timeout(function(){
    $scope.values = [
        { 'Name': "Accepted", 'Value': "Accepted" },
        { 'Name': "Not accepted", 'Value': "NotAccepted" },
        {'Name': "Not at all accepted", 'Value': "NotAtAllAccepted" }
      ];
    $scope.selectedValue = "Accepted";
  }, 2000);
  
  
  //$scope.selectedValue = "NotAccepted";
  //$scope.selectedValue = "NotAtAllAccepted";
});
<!DOCTYPE html>
<html ng-app="plunker">

  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <script>document.write('<base href="' + document.location + '" />');</script>
    <link rel="stylesheet" href="style.css" />
    <script data-require="angular.js@1.3.x" src="https://code.angularjs.org/1.3.20/angular.js" data-semver="1.3.20"></script>
    <script src="app.js"></script>
  </head>

  <body ng-controller="MainCtrl">
    <p>Hello {{selectedValue}}!</p>
    
    <select ng-model="selectedValue" ng-options="orderStatus.Name as orderStatus.Value for orderStatus in values"></select>
    
  </body>

</html>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!