这是我的观点:
<!doctype html>
<html lang="en" ng-app="LunchCheck">
<head>
<title>Lunch Checker</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="angular.min.js"></script>
<script src="app.js"></script>"
<link rel="stylesheet" href="styles/bootstrap.min.css">
<style>
.message { font-size: 1.3em; font-weight: bold; }
</style>
</head>
<body>
<div class="container" ng-controller="LunchCheckController">
<h1>Lunch Checker</h1>
<div class="form-group" >
<input id="lunch-menu" type="text"
placeholder="list comma separated dishes you usually have for lunch"
class="form-control" ng-model="input">
</div>
<div class="form-group">
<button class="btn btn-default" ng-click="stack()">
Check If Too Much
</button>
</div>
<div class="form-group message" id="result">
<!-- Your message can go here. -->
{{message}}
</div>
</div>
</div>
</div>
</body>
</html>
这是我的JS:
(function() {
'use strict';
angular.module('LunchCheck', [])
.controller('LunchCheckController', LunchCheckController);
LunchCheckController.$inject = ['$scope'];
function LunchCheckController ($scope) {
$scope.input = "";
$scope.message = "";
$scope.stack = function($scope, input) {
var array = $scope.input.split(',');
if (array.length <= 3) {
$scope.message = "Enjoy";
} else if (array.length > 3){
$scope.message = "Please stop!";
} else ($scope.input == " " || Null ) {
$scope.message = "Please enter something."
}
};
}
};
}
})();
我的问题基本上在我尝试使用时都开始:
else ($scope.input == " " || Null ) {
$scope.message = "Please enter something."
}
我是一个完整的初学者,但是我不确定自己在做什么错。抱歉,如果太乱了,我可能粘贴和编辑的内容太多了。
基本上,当我尝试在浏览器中打开它时,在输入窗口下显示双大括号,说{{ message }}
基本上,当我尝试在浏览器中打开它时,在输入窗口下显示双花括号,并显示
{{ message }}
[当您看到双方括号({{ }}
)时,通常意味着AngularJS框架未加载。
检查开发人员控制台以获取错误消息。
Uncaught SyntaxError:意外的令牌{ app.js:20
问题出在第20行:
function LunchCheckController ($scope) {
$scope.input = "";
$scope.message = "";
$scope.stack = function($scope, input) {
var array = $scope.input.split(',');
if (array.length <= 3) {
$scope.message = "Enjoy";
} else if (array.length > 3){
$scope.message = "Please stop!";
̶}̶ ̶e̶l̶s̶e̶ ̶(̶$̶s̶c̶o̶p̶e̶.̶i̶n̶p̶u̶t̶ ̶=̶=̶ ̶"̶ ̶"̶ ̶|̶|̶ ̶N̶u̶l̶l̶ ̶)̶ ̶{̶
} else {
$scope.message = "Please enter something."
}
};
}