每次保存myApp.js
时,CodeKit都会给我一个警告。当我通过CodeKit预览加载index.html时,firstName
和lastName
变量显示正常。我只想让这个问题消失。
"var app = angular.module("myApp", []);
'angular' is not defined"
以下是我的两个文件index.html
和myApp.js
的index.html:
<html>
<script src="angular/angular.js"></script>
<script src="myApp.js"></script>
<body ng-app="myApp" ng-controller="myCtrl">
<div>
{{ firstName + " " + lastName }}
</div>
</body>
</html>
myApp.js:
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
$scope.firstName = "John";
$scope.lastName= "Doe";
});
答案 0 :(得分:4)
我没有尝试过Claies的解决方案,但我们在项目中所做的只是将其注册为全局,以便Codekit不会抱怨。只有在确定已定义角度时才执行此操作,否则会隐藏错误。
选项1 - 适用于jshint
将以下内容放入JS文件中:
collect
参考:https://incident57.com/codekit/help.html#jshint
选项2 - 适用于jshint和jslint
或者,您可以在Codekit配置中定义全局变量:
答案 1 :(得分:1)
这是由于Code Linting进程正在主动搜索语法错误而发生的。不幸的是,它没有意识到angular
是您的脚本文件可用的全局变量,因为它是在不同的文件中声明的。它实际上在浏览器(或预览窗格)中工作,但Linting不知道angular
的存在。
您可以在JavaScript文件的顶部添加/// <reference path="angular/angular.js" />
,以通知语法检查器实际声明angular
变量的位置。