- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2019 07:41 AM
I am working on a service portal widget. I want the initial visibility of the widget/button to depend on the result of a server-side call. I've created a function, c.onLoad() that accomplishes this. If I add onLoad="c.onLoad()" to the element, the client and server script run only once as they should.
But if I instead use ng-init="c.onLoad()" or some other AngualrJS directive that calls the onLoad function, the client script appears to run once but the server script runs twice! I was able to verify this with the client and server logs.
I don't see why using the angular directive causes the server script to run twice? Maybe somehow the controller is running twice?
HTML
<div style="padding-bottom:5px;">
<button id="cancel" type="button" class="btn btn-danger btn-block" ng-init="c.onLoad()" >Cancel</button>
</div>
Client
function (spModal) {
/* widget controller */
var c = this;
c.onLoad = function () {
console.log("I only run once");
c.server.get({
...
}).then(function (r) {
...
});
}
}
Server
(function () {
gs.log("CHCEK: I should not run twice");
})();
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2019 08:25 AM
Just e thought: Is it because you execute the service side function IIFE and then with the c.server.get you trigger server side again?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2019 08:25 AM
Just e thought: Is it because you execute the service side function IIFE and then with the c.server.get you trigger server side again?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2019 08:29 AM
Maybe but here's what's interesting: I just commented out the entire client script and the server script is still running when the page loads for some reason. Maybe this isn't angular related?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2019 08:35 AM
Oh yeah, I guess that may be the case. But is there any way to prevent the script from running on load? SN seems to encourage this format as the default?