gpt4 book ai didi

javascript - Angular 不显示输出

转载 作者:行者123 更新时间:2023-11-28 04:17:39 24 4
gpt4 key购买 nike

已经尝试了 stackoverflow 上的所有解决方案,但它不能解决我的问题,我的输出没有显示。输出确实出现在日志和其他任何地方,但由于某种原因, Angular 无法渲染它。

在我的真实场景中,我将从服务器接收数据,并且我模仿了将在“controller.js”文件中获取的对象结构

HTML

<!DOCTYPE html>
<html lang="en">
<head>

</head>

<body>

<div ng-app="application" ng-controller="controller">
<ng-view>

<h2> Todo List: </h2>

<ul>

<li> {{t}}</li>
<li> {{s}}</li>

</ul>


</ng-view>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<script src="application.js"></script>
<script src="controller.js"></script>
</body>

</html>

Controller .js

   var app=angular.module('application', []);
app.controller("controller", function($scope) {
var d= [{'Task':'Say hi!','Status':'failed'}];

$scope.t=d[0].Task;
$scope.s=d[0].Status;

console.log("Task",$scope.t);
console.log("Status",$scope.s);

});

Application.js

var app = angular.module("application", []);
app.run(function(){
console.log("App running!");
});

最佳答案

<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<div ng-app="application" ng-controller="_controller">
<h2> Todo List: </h2>
<ul>
<li> {{t}}</li>
<li> {{s}}</li>
</ul>
</div>

<script>
var app=angular.module('application', []);
app.controller("_controller", function($scope) {
var d= [{'Task':'Say hi!','Status':'failed'}];

$scope.t=d[0].Task;

$scope.s=d[0].Status;

console.log("Task",$scope.t);
console.log("Status",$scope.s);
});


app.run(function(){
console.log("App running!");
});
</script>
</body>

</html>

关于javascript - Angular 不显示输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45692490/

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