JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular-cookies.js"></script>
<div ng-app="myApp">
<div id="lastVal" ng-controller="ShowerCtrl">{{lastVal}}</div>
<div id="button-holder" ng-controller="CookieCtrl">
<input type="text" ng-model="strText" />
<button ng-click="AddItem()">Add Item!</button>
</div>
</div>
JavaScript
var myApp = angular.module('myApp', ['ngCookies']);
myApp.controller('CookieCtrl', function($scope, $rootScope, $cookieStore) {
$scope.strText = "";
$scope.AddItem = function() {
var lastVal = $cookieStore.get('lastValue');
if ($scope.strText) {
if (!lastVal) {
$rootScope.lastVal = new Array(); //Default
$rootScope.lastVal.push($scope.strText);
} else {
var newItem = angular.copy(lastVal);
newItem.push($scope.strText);
$rootScope.lastVal = newItem;
}
$cookieStore.put('lastValue', $rootScope.lastVal);
}
};
});
myApp.controller('ShowerCtrl', function() {});