Seeking a method for one-way (not one time) binding between an attribute on a directive without utilizing attrs.$observe
. Currently considering binding via &attr
and invoking the variables in the template like {{attr()}}
.
app.controller('MainCtrl', function($scope) {
$scope.names = ['Original'];
setTimeout(function () {
$scope.names.push('Asynchronously updated name');
$scope.$apply();
}, 1000);
});
app.directive('helloComponent', function () {
return {
scope: {
'names': '&names'
},
template: '<li ng-repeat="name in names()">Hello {{name}}</li>'
}
});
<body ng-controller="MainCtrl">
<ul>
<hello-component names="names"/>
</ul>
</body>
Plunker
Exploring alternatives that maintain one-way binding without the necessity to invoke the bound properties.
Edit
Clarification added to emphasize the desire to bind to an object, not just a string. Consequently, @attr
(designed for string attributes) is not considered a suitable solution.