[英]Angularjs - get the value to show from a html select
I'm trying to select the Land so I can show it like {{ selectCenter.land }}
but its empty. 我正在尝试选择土地,因此我可以像{{ selectCenter.land }}
一样显示它,但是它是空的。 Can someone see what's wrong? 有人知道出什么事了吗?
Here is a working plunker 这是一个工作的家伙
http://plnkr.co/edit/Q8jhdJltlh14oBBLeHJ9?p=preview http://plnkr.co/edit/Q8jhdJltlh14oBBLeHJ9?p=preview
and code 和代码
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<link rel="stylesheet" href="style.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.20/angular.min.js"></script>
<script src="script.js"></script>
</head>
<body>
<h1>ngOption demo</h1>
<div ng-controller="SelectCtrl">
Search: <input ng-model="searchText" type="text">
<select
ng-model="selectCenter"
ng-options="center.land for center in centre | filter:searchText"
multiple class="form-control input-lg">
</select>
You have chosen:
{{ selectCenter }}
</div>
</body>
</html>
// Code goes here
angular.module("myApp", []);
angular.module("myApp").controller("SelectCtrl", ["$scope", function ($scope) {
$scope.centre = [
{"id":"122","shopID":"200","land":"denmark"},
{"id":"123","shopID":"201","land":"france"},
{"id":"124","shopID":"202","land":"italy"}
];
}]);
Because are you using multiselect your model selectCenter
is an array not a object so you can't show it as 因为您正在使用多选模型, selectCenter
是一个数组而不是对象,因此您无法将其显示为
{{selectCenter.land }}
but you can create repeter like : 但是您可以像这样创建重复器:
<span ng-repeat="center in selectCenter">{{center.land}}</span>
Please see working demo here http://plnkr.co/edit/CXk6ag3XK85JSoWKJYcM?p=preview 请在此处查看工作演示http://plnkr.co/edit/CXk6ag3XK85JSoWKJYcM?p=preview
remove multiselect 删除多选
<select ng-model="selectCenter"
ng-options="center.land for center in centre | filter:searchText"
class="form-control input-lg">
for working code check here 在这里查看工作代码
http://plnkr.co/edit/NUp6OuFty4lbAd4mwn6D?p=preview http://plnkr.co/edit/NUp6OuFty4lbAd4mwn6D?p=preview
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.