Unknown provider $ sce in AngularJS

I'm trying to use $ sce. I installed your code as follows:

var app = angular .module('app', ['ui.router', 'admin', 'home', 'questions', 'ngResource', 'ngSanitize', 'LocalStorageModule','ajoslin.promise-tracker']) .config(['$locationProvider', '$sce', '$sceProvider', '$stateProvider', function ($locationProvider, $sceProvider, $stateProvider) { $sceProvider.enabled(false); $locationProvider.html5Mode(true); 

In the controller:

 angular.module('questions') .controller('QuestionsContentController', ['$rootScope', '$sce', '$scope', '$http', '$resource', '$state', function ($rootScope, $sce, $scope, $http, $resource, $state) { var isNumber = !isNaN(parseFloat($state.params.content)); 

I checked and I have downloaded downloadable angular -sanitize.js v1.2.0-rc.3.

However, I get the message:

 Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to: Error: [$injector:unpr] Unknown provider: $sce 

Can anyone help me out by suggesting what I'm doing wrong. I followed the example as much as possible, but I can not understand what happened.

Some background:

I think I need to get $ sce, because I have data that I trust 100% and that I want to show on the screen. This is data containing "<" ">" "&" and something like this. I set $ sceProvider.enabled (false), but the data is still not displayed correctly. Then I thought what maybe I need to do:

$ Scope.content = data.text; $ Scope.unsanitizedQuestionText ($ sce.trustAsHtml (data.text))

and then in my HTML:

Is it right that I need?

+7
angularjs
source share
2 answers

$ sce is enabled by default starting with angular 1.2-, so you no longer need to sanitize to get $ sce. So, with 1.2, you can pass $ sce as any other service. But make sure your angular is version 1.2 (in case you checked the sanitize vs core version).

+12
source share

The problem is that you are trying to use $ sce, which is a service, inside the module configuration block. In this block, only suppliers available.

Change it

 .config(['$locationProvider', '$sce', '$sceProvider', '$stateProvider', function ($locationProvider, $sceProvider, $stateProvider) { 

For this

 .config(['$locationProvider', '$sceProvider', '$stateProvider', function ($locationProvider, $sceProvider, $stateProvider) { 

Since it seems that the additional $ sce dependency was erroneous anyway. You did not use it, and it was not defined as a parameter.

+10
source share

All Articles