這是我的html:不能從外部JS訪問角服務文件
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/style.css">
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
</head>
<body>
<script type="text/javascript" src="services.js"></script>
<div ng-app="myApp" ng-controller="myCtrl2">
hello {{x}}
</div>
<script>
var app=angular.module("myApp", []);
app.controller("myCtrl2", ['$scope','$location', function($scope, $location) {
myService.set("world");
$scope.x=myService.get();
}]);
</script>
</body>
</html>
,這是我services.js文件:
var app=angular.module("myApp", []);
app.factory('myService', function() {
var savedData = {}
function set(data) {
savedData = data;
}main.html
function get() {
return savedData;
}
return {
set: set,
get: get
}
});
爲什麼沒有我得到的Hello World而是鍍鉻開發人員工具說:ReferenceError:我的服務沒有定義