【发布时间】:2015-02-10 13:54:49
【问题描述】:
我有一个下拉列表。单击按钮时我会调用一个函数。在此我需要我选择的所有值如何做到这一点
以下是我的代码
HTML
<html ng-app="myapp">
<head>
<script src="angular/angular.js"></script>
</head>
<body>
<div ng-app ng-controller="MyCtrl">
<select class="form-control" ng-model="firstType" ng-change="onRegionChange(firstType)" ng-options="item.id as item.name for item in items">
</select>
<input type="submit" ng-click='resultView()'/>
</div>
</body>
</html>
脚本
<script>
var myapp = angular.module('myapp', []);
myapp.controller('MyCtrl', function ($scope,$http)
{
$scope.Data = {};
$scope.items = [{id:1, name:'First'}, {id:2, name:'Second'}, {id:3, name:'Third'}];
$scope.onRegionChange = function(firstType)
{
console.log(firstType);
}
$scope.resultView = function()
{
console.log(firstType);
}
});
</script>
非常感谢任何建议或帮助。
单击按钮时,控制台中显示错误
谢谢 这是错误截图
【问题讨论】:
-
请出示您的
items -
在改变它的工作,但在按钮上点击它的显示 1
-
试试
ng-click="resultView()"而不是ng-click='resultView()' -
两者都知道,但我试过了它不起作用