View不会从AngularJS中的控制器显示正确的模型数据

时间:2016-10-13 02:22:13

标签: javascript angularjs

我正在测试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 }} 

我没有看到正确的格式。 可能有什么不对?

由于

1 个答案:

答案 0 :(得分:2)

您为员工对象分配值的方式存在问题,应该是这样的,

myApp.controller("myController", function ($scope){
    var employee = {
        firstName : "Test",
        lastName : "Name",
        gender : "Male"        
    };
    $scope.employee = employee;    
});

DEMO