0

Newbie to AngularJS! I am getting the controller scope in Javascript with the below code.

javascript

var controller = document.getElementById("listModules");
var controllerScope = angular.element(controller).scope();

controllerScope.$apply(function(){
    controllerScope.newVariable = "test";    
}

html

<div id="listModules" ng-controller="myCtrl"></div>

This is working fine and I am able to create new variable and access it but I want to return HTML from a function which needs $sce inside the scope.

access $sce

controllerScope.$apply(function(){
    controllerScope.newFunc = function(htmlString){
       return $sce.trustAsHtml(htmlString)
    } 
}

I am stuck here to access $sce. Any Ideas?

Hary
  • 5,690
  • 7
  • 42
  • 79
  • 1
    Can you post the html where the listModules id is. Also, Why don't you use the angularjs regular way? – IsraGab Dec 25 '18 at 19:42
  • Would have to inject `$sce`. Where are you running this code? Seems strange to need to do this the way you are doing it – charlietfl Dec 25 '18 at 19:47

0 Answers0