Should be a basic solution but for the life of me I don't see what is wrong.
应该是一个基本的解决方案,但对于我的生活,我没有看到什么是错的。
I am attempting to run an Angular JS application and I am getting a runtime error:
我试图运行Angular JS应用程序,我收到运行时错误:
JavaScript runtime error: 'angular' is undefined
JavaScript运行时错误:'angular'未定义
Here is my code below.
这是我的代码如下。
(function() {
var app = angular.module('MyApp', []);
app.controller('MyAppController', function($scope) {
$scope.message = "Hello, World!";
});
}());
<!doctype html>
<html ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
<script src="js/main.js"></script>
</head>
<body>
<h1> Angular JS App </h1>
<div ng-app="MyApp" ng-controller="MyAppController">
<label> {{message}} </label>
</div>
</body>
</html>
Thank you in advance!
先谢谢你!
1 个解决方案
#1
0
You placed your ngApp directive twice in your view template.
您将ngApp指令放在视图模板中两次。
https://plnkr.co/edit/cSTHyVqMHFVw8ht9mkIr
https://plnkr.co/edit/cSTHyVqMHFVw8ht9mkIr
<body ng-app="app">
<h1> Angular JS App </h1>
<div ng-controller="ctrl">
<label> {{message}} </label>
</div>
</body>
Declaring once will solve your issue.
声明一次将解决您的问题。
#1
0
You placed your ngApp directive twice in your view template.
您将ngApp指令放在视图模板中两次。
https://plnkr.co/edit/cSTHyVqMHFVw8ht9mkIr
https://plnkr.co/edit/cSTHyVqMHFVw8ht9mkIr
<body ng-app="app">
<h1> Angular JS App </h1>
<div ng-controller="ctrl">
<label> {{message}} </label>
</div>
</body>
Declaring once will solve your issue.
声明一次将解决您的问题。