我需要做出一個網頁應用,而無需像app.js的任何其他文件或controller.js角控制器直接的index.html
我創建了下面的例子,但我得到的錯誤: Module 'myApp' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title> JavaScript Angular</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js">
var myАpp = angular.module("myАpp", []);
myАpp.controller("firstController", function($scope){
$scope.test = "test-to-test";
});
</script>
</head>
<body ng-app = "myApp">
<div ng-controller = "firstController">
{{test}}
</div>
</body>
</html>
那麼,是不是可以有隻角一個index.html文件,仍然有內部控制器?
簡單exampe內的控制器和模塊:http://www.w3schools.com/angular/tryit.asp?filename=try_ng_controller –
然而,你的不工作的真正原因是你的'myApp'變量中有一個非ASCII字符。糾正這一點,並調整腳本標籤如下所示。 – Toddsden