我正在尝试创建一个前端应用程序,向用户显示一个文本框,他们可以列出他们通常在午餐时间吃的逗号分隔的项目。一旦输入,用户必须点击“检查是否太多”按钮。角度表达未被识别。程序不能正常工作
我是初学者,对Angular还没有很好的把握。我的程序不起作用。首先,当我在HTML中插入它们时,表达式不被识别。不知道为什么。
我认为我的指令的位置可能有问题,但不是很确定,真的可以使用一些帮助。
(function() {
'use-strict';
angular.module('lunchCheck', [])
.controller('LunchCheckController', function ($scope) {
$scope.numberitems = function() {
var itemstring = $scope.items
var lunchItems = itemstring.split(",")
return length.lunchItems
};
$scope.statement = function() {
if ($scope.numberitems==0) {
return "Please enter data first!"
}
else if (0<$scope.numberitems<5) {
return "Enjoy!"
}
else if ($scope.numberitems>4) {
return "Too much!"
}
};
});
})();
<!doctype html>
<html lang="en" ng-app="lunchCheck">
<head>
<title>Lunch Checker</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<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="items">
</div>
<div class="form-group">
<button
class="btn btn-default"
ng-click="statement">Check If Too Much</button>
</div>
<div class="form-group message" ng-click="statement">
{{statement}}
</div>
</div>
</body>
</html>
哪里是'在页面上angular.js'参考? –
语句是一个函数,所以你需要使用它作为函数'()' – Nilesh