我正在测试AngularJS。
Script.js
var myApp = angular.module("myModule",[]);
myApp.controller("myController", function ($scope){
var employee = {
firstName = "Test",
lastName = "Name",
gender = "Male"
};
$scope.employee = employee;
});
的index.html
<html ng-app="myModule">
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="Scripts/angular.min.js" type="text/javascript"></script>
<script src="Scripts/Script.js" type="text/javascript"></script>
</head>
<body ng-controller="myController">
<div>
{{ employee.firstName }}
</div>
<div>
{{ employee.lastName }}
</div>
<div>
{{ employee.gender }}
</div>
</body>
</html>
当我运行程序时,我只看到
{{ employee.firstName }}
{{ employee.lastName }}
{{ employee.gender }}
我没有看到正确的格式。 可能有什么不对?
由于
答案 0 :(得分:2)
您为员工对象分配值的方式存在问题,应该是这样的,
myApp.controller("myController", function ($scope){
var employee = {
firstName : "Test",
lastName : "Name",
gender : "Male"
};
$scope.employee = employee;
});