Define value in client script

YashikaG
Tera Contributor

Hello team, how can I define value in client script in Service Portal and how to show it in HTML?

1 ACCEPTED SOLUTION

Not applicable
Hello @YashikaG ,
Use can use below code. It will work.
var c = this; 
$scope.val = "val1";
c.data.sndval = "val2";
 
HTML:
<p>
    {{c.data.sndval}}
  </p>
  <p>{{val}}</p>
<p ng-bind="data.sndval">
  
</p>
 
<p ng-bind="val">
  
</p>

Please mark my response correct and helpful, if it helps you.
Please reply if any issue happens.

View solution in original post

5 REPLIES 5

Not applicable
Hello @YashikaG ,
Use can use below code. It will work.
var c = this; 
$scope.val = "val1";
c.data.sndval = "val2";
 
HTML:
<p>
    {{c.data.sndval}}
  </p>
  <p>{{val}}</p>
<p ng-bind="data.sndval">
  
</p>
 
<p ng-bind="val">
  
</p>

Please mark my response correct and helpful, if it helps you.
Please reply if any issue happens.

Ravi Gaurav
Giga Sage

Hello @YashikaG 

Client scripts in Service Portal use AngularJS-style bindings to interact with widgets

Example :-

function($scope) {
// Define a value in the client script
$scope.data.myValue = "Hello, Service Portal!";
}

You can use AngularJS bindings ({{ }}) in the HTML template of the widget to display the value defined in the client script.

<div>
<h2>{{data.myValue}}</h2>
</div>

Hi @YashikaG 

 

what was wrong in my answer? could you please clarify ?

 

 

yuvarajkate
Giga Guru

Steps to Follow:

  1. Define Value in Client Script

    • Use $scope to define and set a value in your client script.
    • Example:
      function($scope) {
          $scope.message = "Hello, Service Portal!";
      }
  2. Show Value in HTML

    • Use AngularJS expressions ( {{ }} ) to display the value in the HTML template.
    • Example:
      <div>
          {{message}}
      </div>

Full Example:

Client Script

function($scope) {
    // Set the value
    $scope.greeting = "Welcome to the Service Portal!";
}

HTML Template

<div>
    <h2>{{greeting}}</h2>
</div>