client controller is not working

hemantnh
Tera Expert
when i added $scope in the client controller for my existing code is not working the existing and $scope code, 
 
what is wrong in this ?
 
my exiting code :(used to pass the input values from cline to server side)
 
   c.passvalue = function(checkStatus) {
        c.data.value = checkStatus;
        //$window.alert('approvalState');
        c.server.update();
    }
 
after adding the $scope to the existing code one , the above code is not working 
 
 
api.controller = function($scope) {
   c.passvalue = function(checkStatus) {
        c.data.value = checkStatus;
        //$window.alert('approvalState');
        c.server.update();
    }
 
$scope.totalINC =$scope.data.incidents.length;
$scope.maxInc =10;
$scope.currentIndex=0;
$scope.pageNum= Math.cell($scope.totalINC/$scope.maxInc);
$scope.currentPage=0;
 
$scope.getNumber =function(){
return new Array($scope.pageNum);
}
}
1 ACCEPTED SOLUTION

Robbie
Kilo Patron
Kilo Patron

Hi @hemantnh,

 

Let's set the context and understanding here.

As @Upender Kumar very nicely and clearly explains in the below article, there is a difference between $scope and data. The simple high level difference between them is:

 

$scope is the binding part between HTML (view) and JavaScript (controller)

data is the variable used on the server side which can be leveraged to retrieve values which you can pass to client-side/HTML.

 

$scope:

The Scope in Angular JS is the binding part between HTML (view) and JavaScript (controller) and it is a built-in object. It contains application data and objects. It is available for both the view and the controller. It is an object with available properties and methods. There are two types of scopes in Angular JS.

 

Example usage:

Client Side:

$scope.carname = "Volvo";

HTML

<h1>{{carname}}</h1>

 

data:

is the variable used on the server side which can be leveraged to retrieve values which you can pass to client-side/HTML.

 

Example usage:

Server Side:

data.msgClass='alert-success';

HTML:

<div class="{{data.msgClass}}"></div>

 

What are you trying to achieve?

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.



Thanks, Robbie

 

Article link: https://www.servicenow.com/community/developer-forum/service-portal-how-to-use-scope-and-quot-data-q...

View solution in original post

1 REPLY 1

Robbie
Kilo Patron
Kilo Patron

Hi @hemantnh,

 

Let's set the context and understanding here.

As @Upender Kumar very nicely and clearly explains in the below article, there is a difference between $scope and data. The simple high level difference between them is:

 

$scope is the binding part between HTML (view) and JavaScript (controller)

data is the variable used on the server side which can be leveraged to retrieve values which you can pass to client-side/HTML.

 

$scope:

The Scope in Angular JS is the binding part between HTML (view) and JavaScript (controller) and it is a built-in object. It contains application data and objects. It is available for both the view and the controller. It is an object with available properties and methods. There are two types of scopes in Angular JS.

 

Example usage:

Client Side:

$scope.carname = "Volvo";

HTML

<h1>{{carname}}</h1>

 

data:

is the variable used on the server side which can be leveraged to retrieve values which you can pass to client-side/HTML.

 

Example usage:

Server Side:

data.msgClass='alert-success';

HTML:

<div class="{{data.msgClass}}"></div>

 

What are you trying to achieve?

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.



Thanks, Robbie

 

Article link: https://www.servicenow.com/community/developer-forum/service-portal-how-to-use-scope-and-quot-data-q...