I'm working on an Angularjs project using .component()
with template
property, but I don't know how to use templateUrl
.
Is there anyone familiar with that can provides me a working example?
Thanks.
To use the angular component properly I recommend using controllerAs syntax.
angular.module('myApp')
.component('groupComponent', {
templateUrl: 'app/components/group.html',
controller: function GroupController(){
this.innerProp = "inner";
},
controllerAs: 'GroupCtrl',
bindings: {
input: '<'
}
});
And on group.html you can consume at the following way:
<div>
{{GroupCtrl.input}}
{{GroupCtrl.inner}}
</div>
From the parent control You can pass any parameter as binding to the component, in this case from the parent HTML:
<group-component input="someModel">
</group-component>