The code works with two-way data binding. But I have this constraint, no = but <.
When I run for the first time the application, the text inputs will have initial hard-coded values. I want to be able to write new values in the inputs and send them to the controller.
Is this possible in one-way data binding?
I will put my code to be more clear.
This is my controller:
class DemandCtrl {
constructor(ChartDataService) {
this.ChartDataService = ChartDataService;
debugger;
this.dataa = {
from: '10/01/2017',
to: '10/03/2017'
};
}
$onInit() {
getData.call(null, this);
}
update() {
getData.call(null, this);
}
function getData(DemandCtrl) {
debugger;
DemandCtrl.ChartDataService.getData(DemandCtrl.dataa).then(result => {
DemandCtrl.result = result.data;
getChart(result.data);
}).catch((e) => {
console.log(e);
});
}
...
DemandCtrl.$inject = ['ChartDataService'];
export const Demand = {
bindings: {
data: '<'
},
templateUrl: demandPageHtml,
controller: DemandCtrl
};
This is the html page:
<div class="demand page">
<rtm-nav from="$ctrl.dataa.from", to="$ctrl.dataa.to", submit="$ctrl.update()">
</rtm-nav>
</div>
And rtm-nav component:
<div class="rtm-nav">
<div ng-app>
<form ng-submit="$ctrl.submit()">
<label>From:
<input type="text" name="input" ng-model="$ctrl.from">
</label>
<label>To:
<input type="text" name="input" ng-model="$ctrl.to">
</label>
<input type="submit" id="submit" value="Apply" />
</form>
</div>
</div>
This is the controller of the component. If I change < to =, everything works as I want but can I do it without changing it?
const rtmNav = {
bindings: {
from:'<',
to:'<',
submit: '&'
},
controller: angular.noop,
templateUrl: require('./rtmNav.html')
}
export default rtmNav;
<input>elements and output changes with expression,'&'binding.