使用角度ng-change获取当前值?

时间:2018-09-21 07:52:47

标签: angularjs flask

我正在尝试使用ng-change从选择列表中获取用户选择的值,但我似乎找不到出问题的地方:

每次我选择其他任何选项时,都会得到“ Sam”,我的问题是如何获取用户选择的值,而不是默认的“ Sam”

这是html:

    <body ng-app="myApp" ng-controller="myCtrl">
<div>
<p>  Employee Name/Employee ID:
                <select ng-model="pickEmp" ng-change="setEmployee(pickEmp)">
                     <option ng-value="James">James</option>
                     <option ng-value="Sam">Sam</option>
                     <option ng-value="Patrick">Patrick</option>
                </select>
            </p>
</div>
</body>

这是JS

var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope,$http) {
    $scope.formObject = {
                         empId:'Sam',
                         que1:{
                            status:'YES',
                            payBand:0-11
                         }
$scope.setEmployee = function(){
    $scope.pickEmp = $scope.formObject.empId;

    }

1 个答案:

答案 0 :(得分:0)

Private Sub Worksheet_Change(ByVal Target As Range) MsgBox "Number of cells changed: " & Target.Cells.Count & vbLf & _ "Changed cell(s): " & Target.Address & vbLf & _ "Cell value changed to: " & _ IIf(Target.Cells.Count > 1, "(Multiple values)", Target) End Sub 函数中,您将ng-model设置为值setEmployee。删除该行。

sam
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope,$http) {
    $scope.formObject = {
                         empId:'Sam',
                         que1:{
                            status:'YES',
                            payBand:0-11
                         }}
$scope.setEmployee = function(){
   console.log($scope.pickEmp)

    }
    
    })