vendredi 4 mars 2016

fix parsing error when using $sce service on html file for a unit test

I am trying to parse a file that I accessed with node's file system (fs). However, I am coming across an error

Error: [$parse:syntax] Syntax Error: Token '<' not a primary expression at column 1 of the expression [<div class="container">

I set up the file through the path. I used readFileSync to get the contents and set them to utf8. That gave me the contents back.

I used a $sce method to get it passing through. Which in my console logs great. However, I am continually getting the error message.

    var template = $sce.parseAsHtml(fs.readFileSync('../Directory/Templates/template.html', 'utf8'));

I went through and set up my directive as so...

 element = angular.element("<div explore-hero></div>");
        //ctrl = _$controller_('ExploreHeroController', { $scope: $scope });
        ctrl = _$controller_;
        $compile(element)($scope);
        $scope.$digest();

We are using jsDom for our tests so we are not using a browser. However, there are some challenges that come with it. Testing templateUrl is one of them. Hoping I can fix the file through this process to get the controller and scope.

Aucun commentaire:

Enregistrer un commentaire