I have a question that concerns conditional partial-a-like views in AngularJS. The example below isn't very optimal. It also returns an error that belongs to the line $compile(element.contents())(scope) that says that I can't use scope as a function - but otherwise it won't render everything correctly. The use case is as following:
I'm requesting a Route over
$httpthat returns a array of objectsI'm
ng-repeatthat returned array of objectsFor every object (lets call it
obj) aobj.view_editvalue is given.If the
obj.typeequalsplugin, a<plugin></plugin>directive is inserted
That would look like:
<plugin view="content.view_edit"></plugin>
My Directive looks like:
directive('plugin', function($compile) {
var linker = function(scope, element, attrs) {
console.log(scope.view);
element.html(scope.view).show();
$compile(element.contents())(scope);
}
return {
restrict:"E",
link: linker,
scope: {
view:'='
}
}
})
Do you have any better solutions?