logo

NJP

Service Portal: Communicating between the Client Script and the Server Script of a widget

Import · Feb 02, 2017 · video

today we're going to create a simple widget to demonstrate how the UI and controller can make calls to the server script in this example we'll have a simple list to which you can add or remove messages I've already prepared a simple form we can use let's get started first let's create an empty server side array that we can store our messages in [Music] [Music] now let's add a data binding to the input box using ng model let's set it to see data message next let's add to ng click to the button so we can do something with our message we'll call the function add alright so now let's test this with console dot log to make sure the add function is getting called okay great Network now let's use the server dot update method to call the server script with surfer update whatever is on data will automatically become input in the server script we can pass information to the server script by simply placing it on data in this case we'll call it add message and pass the value from our input you have to also remember to unset the value within the callback function so that it only executes one [Music] so now on the server side we can check for add message on input and add the message to the end of our array let's move over to the HTML and add the ng-repeat so we can loop over our messages in the array if we have done all this correctly we should now be able to add messages to our list cool looks like that worked to remove messages will need to add an ng-click and pass in the numeric index to the remove method now we can create the remove method on the controller just as before we'll create a property called remove message on data now for the server side we can use the numeric index to splice the message from the array alright let's test it out cool that looks good now to finish it off let's just add a quick message for when the array is empty all right and there you have it now you can see how the client-side can interact with the server script thanks for watching [Music]

View original source

https://www.youtube.com/watch?v=sr_gqqxllRM