Service Portal says "$scope is not defined"

amwebaz
Kilo Expert

When I run the following code  in my Client Script on the Service Portal. The console reports: $scope is not defined.

Does anyone have knowledge on this?

 

(function($location) {
/* widget controller */
var c = this;

function checkLocation() {
var loc = $location.search();
if (loc.table == 'sc_cat_item') {
alert("works");
}
}


$scope.$on('$locationChangeSuccess',function() {
checkLocation();
});

checkLocation();
})();

1 ACCEPTED SOLUTION

Hi amwebaz,

 

$scope should be an argument of client controller, and the function should not be immediately invoked:

function($scope, $location) {
  /* widget controller */
  var c = this;
  function checkLocation() {
    var loc = $location.search();
    if (loc.table == 'sc_cat_item') {
      alert("works");
    }
  }

  $scope.$on('$locationChangeSuccess',function() {
    checkLocation();
  });
  checkLocation();
}

View solution in original post

5 REPLIES 5

@vitaly.sukharev ,

I am also facing the above mentioned issue due to $scope.

Have tried modifying the code as below :

api.controller = function($scope) {
/* widget controller */
var c = this;
function hideResponse() {
if ($scope.data.response) {
$scope.data.response = '';
}
}
$scope.hideResponse();
};

Can you please confirm if this is the correct way to call $scope as an argument of client controller?

Thank you,

Ayshee Chattopadhyay