- 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
01-05-2022 05:08 AM
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