select ng-option & selelct option value 区别

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.bootcss.com/angular.js/1.4.6/angular.min.js"></script>
</head>
<body>

<div ng-app="myApp" ng-controller="myCtrl">
  // ng-option 遍历的方式
  <select ng-model="selectedName" ng-options="x for x in names"></select>
  // 将值绑定在 value 
  <select ng-model="selectedName2">
    <option value="['Google','baidu']">['Google','baidu']</option>
    <option value="['Runoob', 'Taobao']">['Runoob', 'Taobao']</option>
  </select>
</div>

<script>
  var app = angular.module('myApp', []);
  app.controller('myCtrl', function($scope) {
  $scope.names = [['Google','baidu'], ["Runoob", "Taobao"]];
  $scope.selectedName = $scope.names[0];
  $scope.selectedName2 = "['Google','baidu']";
  console.log(typeof $scope.selectedName) // object
  console.log(typeof $scope.selectedName2) // string
});
</script>

</body>
</html>

posted @ 2018-09-06 15:52  余生。请多指教  阅读(392)  评论(0编辑  收藏  举报