gpt4 book ai didi

javascript - AngularJS 中的 View 不显示来自 Controller 的正确模型数据

转载 作者:行者123 更新时间:2023-12-02 14:06:34 24 4
gpt4 key购买 nike

我正在测试 AngularJS,如下所示。

脚本.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 }}

我没有看到正确的格式。可能出了什么问题?

谢谢

最佳答案

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

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

DEMO

关于javascript - AngularJS 中的 View 不显示来自 Controller 的正确模型数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40011266/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com