我正在嘗試創建一個前端應用程序,向用戶顯示一個文本框,他們可以列出他們通常在午餐時間吃的逗號分隔的項目。一旦輸入,用戶必須點擊「檢查是否太多」按鈕。角度表達未被識別。程序不能正常工作
我是初學者,對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