晚安!
我正在尝试实现 ASP.NET API,但我不明白为什么我的 Angular 无法正确编译!
我刚刚创建了一个新的空网络项目,添加了 Angular 和 jquery通过 NUGET,我正在尝试添加这样的脚本。
索引.html
<!DOCTYPE html>
<html>
<head ng-app="palladarApp">
<title>CodeBranch - Palladar</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
</head>
<body ng-controller="palladarCtrl">
<div>
<header></header>
<section>{{ teste }}</section>
<hr />
<section>{{ 13 + 31 }}</section>
<footer></footer>
</div>
<!--Load Libraries-->
<link href="Content/bootstrap.min.css" rel="stylesheet" />
<script src="Scripts/jquery-2.1.4.js"></script>
<script src="Scripts/angular.js"></script>
<script src="Scripts/i18n/angular-locale_pt-br.js"></script>
<script src="Scripts/angular-route.js"></script>
<script src="Scripts/angular-animate.js"></script>
<!--Load Scripts-->
<script src="app/Controllers/palladarController.js"></script>
</body>
</html>
PalladarController.js
var app = angular.module('palladarApp', []);
app.controller('palladarCtrl', ['$scope', '$http', '$modal', function($scope, $http, $modal) {
$http.defaults.headers.post['Content-Type'] = 'application/json';
$scope.teste = "HUE HUE HUE";
}]);
当我运行该项目时,我只是在浏览器中看到了代码..
{{ teste }}
{{ 13 + 31 }}
如果我打开浏览器控制台 (F12),它不会显示任何错误。
最佳答案
您需要将: ng-app="palladarApp"
放在 html 标记内,如下所示:
<!DOCTYPE html>
<html ng-app="palladarApp">
<head>
<title>CodeBranch - Palladar</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
</head>
<body ng-controller="palladarCtrl">
<div>
<header></header>
<section>{{ teste }}</section>
<hr />
<section>{{ 13 + 31 }}</section>
<footer></footer>
</div>
<!--Load Libraries-->
<link href="Content/bootstrap.min.css" rel="stylesheet" />
<script src="Scripts/jquery-2.1.4.js"></script>
<script src="Scripts/angular.js"></script>
<script src="Scripts/i18n/angular-locale_pt-br.js"></script>
<script src="Scripts/angular-route.js"></script>
<script src="Scripts/angular-animate.js"></script>
<!--Load Scripts-->
<script src="app/Controllers/palladarController.js"></script>
</body>
</html>
关于javascript - ASP.Net 不编译 AngularJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32773226/