Angular 1.5 Component: passing a function
If you want to call the function from inside a component and have it return a value then you need two-way binding:
"bindings": {
"posts": "<",
"loading": "<",
"getPostUrl": "=", // <-- two-way binding
"isUserAuthenticate": "<"
},
However, this is probably not very good idea. Consider passing data to component rather than making component request data from outside. This will make much better isolated component.
You can pass functions to components, but you must define the function arguments as object with the correct arguments names as its keys. example:
<post-list posts="blog.posts"
loading="blog.loadingPosts"
get-post-url="blog.getPostUrl(postId)"
is-user-authenticate="blog.user">
</post-list>
const PostList = {
"bindings": {
"posts": "<",
"loading": "<",
"getPostUrl": "&", //Function getPostUrl
"isUserAuthenticate": "<"
},
"template": `<post creation-date="{{post.creationDate}}"
content="{{post.content}}"
post-url="{{$ctrl.getPostUrl({postId:post.creationDate})}}">
</post>