I want to build a custom directive where I can pass an object and depending on that object render a different HTML.
Let's say that the object look's like this.
$scope.obj = {
type: 'input',
placeholder: 'Some text…',
name: 'first_name'
}
The custom directive should look like this (I guess)
<renderObj data="obj" />
This should render a input field with the given data. I guess I have to use either the link
or compile
method within the directive, but how? Notice that the obj
could have many different types of data and would be more complex than this simple example. So I must be able to decide within the directive what to render with which data.
Maybe I don't need a custom directive at all and use ng-include
instead?