This is my view
<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="LunchCheckController()">
Check If Too Much
</button>
</div>
<div class="form-group message" id="result">
<!-- Your message can go here. -->
{{stack()}}
</div>
</div>
This is my JavaScript
(function() {
'use strict';
angular.module('LunchCheck', [])
.controller('LunchCheckController', LunchCheckController);
LunchCheckController.$inject = ['$scope'];
function LunchCheckController ($scope) {
$scope.input = ""; //Taking input from the user
$scope.stack = function(input) {
var array = input.split(',');
if (array.length < 3) {
return "Enjoy";
} else {
return "You gotta Stop boy!";
} // Splitting the input
};
}
})();
I am kinda new to Angular.js. My aim is to get the string and split it. After splitting I want to satisfy a situation where "If the number of items are more than 3,print enjoy" otherwise "Anything else".
$scope.stackis incorrect. If you do have yourif/elseafter areturn, then it will never execute.stack(...)<button class="btn btn-default" ng-click="LunchCheckController()">looks wrong.