无法在ng init方法内部呈现angular指令templateURL



在nginit方法中呈现指令时遇到问题。

第一条指令:控制器:

$scope.addDetails(asset) {
  asset.label = "<div window></div>";
};
return {
            restrict: "EA",            
            scope: true,
            controller: "demoController",
            controllerAs: "vms",
            template: 
            "<div data-ng-repeat = 'data in vms.details' ng-init='vms.addDetails(data);'" +
            </div>"
        };

窗口指令:

return {
              restrict:"AE",
              templateURL: "infowindow.html"
         };
        With the below approach it worked with me we shouldn't do any complex logic(DOM rendering) when we use ng-repeat with ng-init. if so we need to construct the directive after the data is rendered.
        $scope.details= {asset:1,description:"sample text"};
        $scope.addLabel(asset) {
          asset.label = "sample text to be shown in other directive";
        };
        return {
                    restrict: "EA", 
                    bindToController: {details:'='}
                    scope: true,
                    controller: "demoController",
                    controllerAs: "vms",
                    template: 
                    "<div data-ng-repeat = 'data in vms.details' ng-init='vms.addLabel(data);'" +
    "<div window label-text=data.label></div>" +
                    </div>"
                };

窗口指令:

return {
              restrict:"AE",
              bindToController:{labelText: '@'},
              scope:true,
              templateURL: "infowindow.html"
         };

infowindow.html

<div>{{vms.labelText}}</div>

最新更新