- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2018 07:11 AM
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();
})();
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2018 11:53 PM
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();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2018 07:14 AM
hi,
(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();
})();
try once.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2018 07:21 AM
Thanks that worked, but now I get the following:
TypeError: Cannot read property '$on' of undefined
(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();
})();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2018 10:16 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2018 11:53 PM
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();
}