I try to set a scope variable within a template on ng-click and later read it in the controller. Example:
HTML:
<section id="editCtrl" data-ng-controller="EditCtrl as edit">
{{ edit.myVar = []; "" }}
Click the following buttons:<br>
<span data-ng-click="edit.myVar['entry'] = 'test'">Click me</span>
<span data-ng-click="edit.showMyVar();">Show MyVar in console</span>
</section>
JS:
// This controller is just for the example - I would never add a controller variable within the template
var app = angular.module("app", []);
app.controller("EditCtrl", function(){
var edit = this;
edit.showMyVar = function(){
console.log(edit.myVar);
};
});
However the variable "edit.myVar" keeps beeing an empty array. What am I doing wrong? In my interpretation this is a valid ng-click expression.
Live example: JSFiddle
