I have a problem in the directive templateURL it's returning this error and I tried several solutions online but none seem to work

Viewed 22
angular.module('myApp').directive('multiSelectDropdown', function ($sce) {
    return {
        restrict: 'E',
        scope: {
            options: '=',
            field: '=',
            countSelected: '='
        },
        templateUrl: 'C:\Users\\user\\source\\repos\\WebApplication4\\WebApplication4\\Views\\Home\\multiSelectDropdown.cshtml'
    };
});

and this is the error : angular.js:11706 Error: [$sce:insecurl] Blocked loading resource from url not allowed by $sceDelegate policy. URL: C:Users\user\source\repos\WebApplication4\WebApplication4\Views\Home\multiSelectDropdown.cshtml

does anyone know how to solve it ? sorry I'm still a beginner

1 Answers

The error basically says that the TemplateUrl you are trying to request is not safe, you have to mark it safe by using $sce service.

Modify your url assignment as below :

      templateUrl: $sce.trustAsResourceUrl('C:\Users\\user\\source\\repos\\WebApplication4\\WebApplication4\\Views\\Home\\multiSelectDropdown.cshtml')

Related