In the HTML, include a text field and bind it to the application using the ng-model directive.
In the controller, create a function named addItem that takes the value from the addMe input field to add an item to the products array.
Then, add a button with an ng-click directive that triggers the addItem function when the button is clicked.
We can now add items to our shopping list.
<script>
var app = angular.module(“myShoppingList”, []);
app.controller(“myCtrl”, function($scope) { $scope.products = [“Milk”, “Bread”, “Cheese”]; $scope.addItem = function () { $scope.products.push($scope.addMe); } }); </script>
<div ng-app=”myShoppingList” ng-controller=”myCtrl”> |