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>css

<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>html

<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>app

</body>
</html>cdn

相關文章
相關標籤/搜索