我是angularJs的新手。我不理解为什么下面的代码不起作用。浏览器未加载文件myjavascriptcode.js。如果开关
"<script src="./myjavascriptcode.js"></script>"
在角度导入之前已加载文件myjavascriptcode
,但出现异常"angular is not defined"
。使它正常工作的唯一方法是
"<script src="../../angular-1.5.8/angular.js"></script>"
在html标记之前。
jsdemo.html
<!DOCTYPE html>
<html>
<head>
<title>To do</title>
<script src="../../angular-1.2.5/angular.js" />
<script src="./myjavascriptcode.js"></script>
</head>
<body>
This is a simple example
</body>
</html>
./ myjavascriptcode.js
function printMessage(unknownObject){
if( angular.isFunction(unknownObject) ){
unknownObject();
}else{
console.log("mi hai passato una variabile not function");
}
};
var variable1 = function sayHello(){
console.log("Hello");
}
var variable2 = "GoodBye!";
printMessage(variable1);
printMessage(variable2);
enter code here
答案 0 :(得分:0)
您的角度标记未正确关闭,这就是为什么未加载JavaScript
<script src="../../angular-1.2.5/angular.js"></script>
<script src="./myjavascriptcode.js"></script>