I want to achieve two way data binding between the view and the controller who glued by the component in AngularJS version 1.5.
The main purpose is to make a page (which is a component by itself) to handle sub-components accessing referred data.
For example, I have page name: Dashboard.
I want that this page will contain HeaderComponent ListComponent and a FooterComponent.
And I want to pass data from the Dashboard component or from the root component ($rootScope) to the ListComponent for example,
like this:
<list-component key="123"></list-component>
However I cannot find a way to access the key attribute in the ListComponent either component or controller.
This is what I have tried:
// list.js component
app.component('listComponent', {
templateUrl: "/shared/list/list.html",
bindings: {
key: '='
},
controller: function() {
console.log(key);
// or maybe
console.log(this.key);
}
});
Later I will use the key in the HTML with AngularJS default directives as a two way data binding. But so far I cannot access the key attribute yet.
Thank you ;)
<for inputs and expression binding with&for outputs. This will make the migration to Angular 2+ easier. For more information, see AngularJS Developer Guide - Component-based application architecture.key="123"will fail with an error. See AngularJS Error Reference - Error: $compile:nonassign Non-Assignable Expression.