Here is my directive:
a.directive("popupWindowContent", function ($templateRequest, $compile) {
return {
scope: {},
controller: "@",
name: "controllerName",
link: function (scope, elem, attrs) {
scope.data = JSON.parse(attrs.data.replace(/\*/g, '"'));
$templateRequest(attrs.template).then(function (html) {
var template = angular.element(html);
$(elem).append(template);
template = $compile(template) (scope);
});
}
};
});
Markup:
<div popup-window-content controller-name="templateController"></div>
What I am trying to do is to load a template and its controller at the run
time. The code basically works. My problem is I need to have scope.data
defined before the controller loads, but that is not happening.
On Sun, Feb 14, 2016 at 3:23 AM Sander Elias <[email protected]> wrote:
> Injecting the scope?
>
>
> app.controller('aController',
> ['$scope',
> function ($scope) {
> $scope.test = '123456';
> }]);
>
> Or compiling the template before adding it to the dom?
>
> link: function (scope, elem, attrs) {
> $templateRequest("template.html").then(function (html) {
>
> template = $compile(html)(scope);
> elem.append(template);
> });
> }
>
> Is that what you are looking for?
>
> Regards
> Sander
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "AngularJS" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/angular/OY9hODyW7jM/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/angular.
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.