下拉列表更改时,ng-Options 不刷新有线标签

ng-Options is not refreshing the wired label when drop-down changed

遵循 Scott Allen 的第一个代码(简单)sample,在下拉条目更改后,有线 ng-model 不会刷新此

{{engineer.currentActivity}}

浏览器:FF 50.1.0

Angular: 1.5.9

jQuery: 1.7

HTML:

<div ng-controller="EngineeringController">
        {{engineer.name}} is currently : {{engineer.currentActivity}}
        <div>
            choose an activity:
            <select id="agDDLClient" ng-model="EngineeringController.currentActivity" ng-options ="act for act in activities">
            </select>
        </div>
        <input type="button" ng-click="what()" value="check" />
    </div>

JS:

var aIS = angular.module("app", []);
aIS.controller("EngineeringController", function($scope, $http)
{
    $scope.engineer = {
    name: "Dani",
    currentActivity: "Fixing bugs"
};

$scope.activities =
[
    "Writing code",
    "Testing code",
    "Fixing bugs",
    "Dancing"
];

$scope.what = function(){ alert($scope.engineer.currentActivity);}
});

更改为 ng-model="engineer.currentActivity" 而不是 ng-model="EngineeringController.currentActivity"

你的控制器代码也应该遵循这个

var aIS = angular.module("app", []);
aIS.controller("EngineeringController", function($scope, $http)
{
    $scope.engineer = {
    name: "Dani",
    currentActivity: "Fixing bugs"


$scope.activities =
[
    "Writing code",
    "Testing code",
    "Fixing bugs",
    "Dancing"
];

$scope.what = function(){ alert($scope.engineer.currentActivity);}
});

ng-model 值应为 engineer.currentActivity 而不是 EngineeringController.currentActivity,因为您正试图提醒 what() 函数内的 $scope.engineer.currentActivity

工作演示:

var myApp = angular.module('myApp',[]);

myApp.controller('EngineeringController',function($scope) {
    $scope.engineer = {
        name: "Dani",
        currentActivity: "Fixing bugs"
    };

    $scope.activities = [
        "Writing code",
        "Testing code",
        "Fixing bugs",
        "Dancing"
    ];

    $scope.what = function() { 
        alert($scope.engineer.currentActivity);
    };
    
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="EngineeringController">
        {{engineer.name}} is currently : {{engineer.currentActivity}}
        <div>
            choose an activity:
            <select id="agDDLClient" ng-model="engineer.currentActivity" ng-options ="act for act in activities">
            </select>
        </div>
        <input type="button" ng-click="what()" value="check" />
    </div>