0

i am using angularjs 1.65 version and its seems that $sce is getting me undefined i have been trying serval times to get it fixed over 3 hours on it.

here is the module :

var app = angular.module('myApp', ['ui.router','ngclipboard','oitozero.ngSweetAlert']);
app.config(function ($stateProvider, $urlRouterProvider, $locationProvider) {})

and here is the controller :

 app.controller('monitormainController',
 ['$rootScope','$scope','$timeout','SweetAlert','$sce',  function
 ($scope,$timeout,$rootScope,$watch,SweetAlert,$sce) {

  $scope.copyset = function(name){ $scope.trustedHtml =
  $sce.trustAsHtml(name); };

 });

i am getting an error which says $sce is undefined

Failed to load resource: the server responded with a status of 404 (File not found) angular.js:14642 TypeError: Cannot read property 'trustAsHtml' of undefined at Scope.$scope.copyset (monitormainController.js:93) at fn (eval at compile (angular.js:15500), :4:153) at callback (angular.js:27285) at Scope.$eval (angular.js:18372) at Scope.$apply (angular.js:18472) at HTMLButtonElement. (angular.js:27290) at HTMLButtonElement.dispatch (jquery.js:5095) at HTMLButtonElement.elemData.handle (jquery.js:4766)

will be happy to get any answer thank you very much!

0

1 Answer 1

2

Your dependencies are in the wrong order here. You must match the order of the dependencies in the array exactly with the parameters in the function. Also, you are expecting $watch in your function, but not including it in the dependency list.

Edit: If you are intending to use $scope.$watch rather than a $watch service that you created or installed, that isn't an injectable service. Therefore, it should not be passed as a function parameter.

Instead of:

['$rootScope','$scope','$timeout','SweetAlert','$sce',  function
($scope,$timeout,$rootScope,$watch,SweetAlert,$sce) {

Try:

['$rootScope','$scope','$timeout','SweetAlert','$sce',  function
($rootScope,$scope, $timeout, SweetAlert, $sce) {
Sign up to request clarification or add additional context in comments.

3 Comments

Still not working :( , changed the way you did . its kind of wired . idk how to say it even, all seems to be okay for that.
angularjs when you install scope are giving you the $watch. from what i have read.
I updated the answer; more than likely, you were expecting to use $scope.$watch rather than some $watch service. removing that should make any errors related to it go away.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.