Angular不工作但没有错误

时间:2016-09-12 08:25:16

标签: javascript angularjs

我的代码未输出{{title}} 'hello world'。虽然角度不起作用但没有给出错误信息。

<!-- HTML -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Angular</title>
</head>
<body np-app="myApp">
<div ng-controller="MainController">
{{ title }}
</div>
<script src="https://code.jquery.com/jquery-2.2.4.min.js"                    integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="   crossorigin="anonymous"></script>`
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
<script type="text/javascript" src="angular.js"></script>
</body>
</html>

// Javascript

var app = angular.module("myApp", []);
app.controller("MainController", ['$scope', function($scope){
    $scope.title = "hello world";
}]);

1 个答案:

答案 0 :(得分:11)

您的正文标记中的拼写错误为<body np-app="myApp">,需要更改为<body ng-app="myApp">

希望这有帮助!