I am just starting with AngularJS and am trying to figure out how to easily reference (bind?) scope variables from outside the Angular controller.
Simple code:
<div ng-controller="Ctrl">
<label>Name:</label>
<input type="text" ng-model="yourNameInput" placeholder="Enter a name here">
<input type="button" onClick="console.log(inputName);">
<hr>
<h1 ng-bind-template="Hello, {{yourNameInput}}"></h1>
</div>
How would I bind {{yourNameInput}}
to inputName
var that will be available to the rest of my application? There's one ugly way I managed to do that:
$scope.change = function() { inputName = $scope.yourNameInput; }
and then:
<... ng-change = "change()">
Anything more elegant?