0
我認爲這將是一個超級簡單的事情,但事實證明它不是。
下面的代碼如何不起作用,我想如果將模型設置爲cookie,它將設置cookie,就像設置var一樣,然後獲取cookie:
的jsfiddle:https://jsfiddle.net/wz3kgak3/5/
<script>
var myApp = angular.module('myApp', ['ngCookies']);
myApp.controller('MyController', function($cookies) {
var THIS = this;
});
</script>
<div ng-app="myApp">
<div ng-controller="MyController as mc">
<label>Name:</label>
<input type="text" ng-model="mc.$cookies.user" placeholder="Enter a name here">
<hr>
<h1>Hello {{mc.$cookies.user}}!</h1>
</div>
</div>