I've created directive widget (which act like ng-view but name of the template is taken from attribute)
app.directive('widget', function() {
return {
restrict: 'EA',
scope: true,
templateUrl: function(tElement, tAttrs) {
var page = tAttrs.name + ".html";
return window.location.href.replace(/[^\/]+$/, '') + page;
}
};
});
it work when I create widget like this:
<widget name="page"/>
It display page.html. But will not work with this code (I know that it will return 404 while typing until I finish, but it's just an example)
<input ng-model="widgetName"/>
<widget name="{{widgetName}}"/>
In order to have this dynamic widget, I need to create template using link function, how can I do this? I only know that I need to create scope using {name: '@name'} to bind it with attribute name and that I can use $http in link function but don't know what do do when I got the page from it.