angularjs 物件對應控制項

  • 707
  • 0

ng-model

<script src="~/Scripts/ngcontroller.js"></script>
<div ng-app="myModule">
    <div ng-controller="myController">

        FirstName:<input type="text" ng-model="employee.FirstName" /><br />
        LastName:<input type="text" ng-model="employee.LastName" /><br />
        Gender:<input type="text" ng-model="employee.Gender" /><br />


    </div>

</div>

ngcontroller.js

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

myApp.controller("myController", function ($scope) {

    var employee = {
        FirstName: "Charles",
        LastName: "Chiang",
        Gender: "Male"
    };

    $scope.employee = employee;
});