1

app.directive("widget", function () {
    return {
        restrict : 'E',
        templateUrl: function (elem, attr) {
            return '/Views/Widget/' + attr.widgettype + '.html';
        },

        controller: function ($scope, $element, dataService) {
            console.log($scope.w.DataUrl);
            dataService.getData($scope.w.DataUrl)
                .then(function (data) {
                        $scope.DataSource = data;

                        $('#' + $scope.w.Name).kendoGrid({
                            columns: PrepareColumns($scope.w.Columns),
                            dataSource: data,
                            scrollable: true,
                            sortable: true
                        });
            });
       },       
    }
});
<div ng-app="WidgetContainer" ng-controller="WidgetContainerCtl">
    <widget ng-repeat="w in UserWidgets" class="panel panel-default" widgettype="{{w.WType}}"></widget>
</div>

Above is the code through which I am trying to achieve

1) Iterate an generate widget tags based on the collection passed. 2) Use the widgettype attribute value to determine the template required.

But the above does not fetch the value for widgettype at following line

return '/Views/Widget/' + attr.widgettype + '.html';

I have already tried using nr-attr-widgettype but that too doesnot work.

2
  • Just found out from Angular Site: " You do not currently have the ability to access scope variables from the templateUrl function, since the template is requested before the scope is initialized." However, you can have another approach. Here is the link you might want to take a look. Dynamic templateUrl - AngularJS Commented Dec 4, 2015 at 19:01
  • thanks let me have a look at it Commented Dec 4, 2015 at 19:06

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.