$uibModal displaying wrong information when clicked for the first time

I'm having an issue with $uibModal in ServiceNow. When I try to open a modal window containing an embedded widget, it opens correctly on the first click but requires two clicks for the content to load properly on subsequent clicks. Some sources suggest it's due to the template cache not clearing and recommend avoiding script tags. However, I'm unsure how to make uibModal work without using script tags in ServiceNow. Has anyone else encountered this problem? Any suggestions on resolving it would be appreciated.

Below is my client script:

c.onWidget2 = function(template, task) {
    c.taskName = task.short_description;
    c.modalInstance = $uibModal.open({
        templateUrl: template,
        scope: $scope,
        size: 'lg'
    });
    spUtil.get('hrj_task_activity_scoped', {
        sys_id: task.sys_id,
        table: 'sn_hr_core_task',
        recordInfo: task.taskInfo
    }).then(function(response) {
        c.newTask2 = response;
    });
};

//closeModal for the "x" 
c.closeModal = function() {
    c.modalInstance.close();
};

And here's my HTML:

<div class="card" ng-click="c.onWidget2('newTask2',task);"></div>

<script>
    <div class="panel panel-default">
        <div class="panel-heading clearfix">
            <h4 class="panel-title pull-left">{{c.taskName}}</h4>
      <span ng-click="c.closeModal()"><i class="fa fa-times pull-right"></i></span>
    </div>
        <sp-widget widget="c.newTask2" options="c.newTaskOptions"></sp-widget>
  </div>
</script>

Answer №1

One issue that arises is the "directive in modal", as discussed in this thread:

Integrating directive in Angular UI Modal

A potential solution is to ensure the directive is loaded after the modal has been rendered:

c.onWidget2 = function(template, task) {
    c.taskName = task.short_description;

    var initWidget =  spUtil.get('hrj_task_activity_scoped', {
        sys_id: task.sys_id,
        table: 'sn_hr_core_task',
        recordInfo: task.taskInfo
    }).then(function(response) {
        c.newTask2 = response;
    });

    c.modalInstance = $uibModal.open({
        templateUrl: template,
        scope: $scope,
        size: 'lg'
    }).rendered.then(initWidget);
};

//closeModal for the "x" 
c.closeModal = function() {
    c.modalInstance.close();
};

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Guide to setting the ng-selected value within AngularJS

I am currently working on a project where I have a select element in my AngularJS application. I am populating the options using JSON values with ng-repeat, and I want to display the first value from the JSON as selected by default. I have tried two diffe ...

The template in AngularJS route fails to display

I am currently facing an issue with loading multiple pages using AngularJS $routeProvider and two controllers. Whenever I click on a link from the first partial to go to the second one, the second partial fails to render properly, displaying only template ...

First time blur update unique to each user

By using ng-model-options="{ updateOn: 'blur' }", I can delay model updating until the user clicks out of an input field. This helps prevent constantly changing validation states while initially entering data. However, if a user revisits a field ...

Distinguishing between AngularJS ng-init and data-ng-initIn AngularJS,

Currently, I am exploring Angular Js and have noticed that some authors use ng-init while others use data-ng-init. Despite my efforts to research, I have been unable to find a clear explanation of the difference between the two. If anyone can shed light on ...

Display or conceal navigation items in AngularJS based on the user's logged-in status

My AngularJS app is a single-page application that works with Express, node.js, and MongoDB using Mongoose. I am also implementing Passport for user management/authentication. I want the navbar items to dynamically change based on whether a user is logged ...

Can you run both Angular 6 and AngularJS 1.6 applications on the same computer?

Trying to juggle the development of an Angular 6 app and an AngularJS 1.6 app on the same machine has posed a challenge for me. My current situation involves working on two projects simultaneously - one being a new project utilizing Angular 6 and Angular ...

Seeing no changes in the view despite updating with 2 AngularJS modules

I built a three module app structure: app.root, app.shell, and app.shop. Here is how it looks: .module('app.root',['app.shell,'app.shop']) In the app.shop module, I have implemented a function to add items to cookies: vm.add = f ...

Generate an array of checked inputs to be used when posting to a REST API

I have been using .push() to create a checked array of "List" inputs for posting to a REST API. However, it doesn't seem to be working correctly. When unchecking an item, it is not automatically removed from the array. Does anyone have a better solut ...

The third column sort click in KendoUI Grid causes the data.sort array in the DataSource parametermap to become undefined

I am currently working with a datagrid configuration that looks like this: <script> angular.module("KendoDemos", [ "kendo.directives" ]); function MyCtrl($scope) { $scope.mainGridOptions = { dataSource: { transport: { ...

Successive promises of catches

Here is a situation that I am dealing with: controller.ts methodA(): void { myServive.someMethod() .then( () => console.log("then") ) .catch( e => { console.log("catch"); }); } service.ts someMethod(): ng: ...

Error Encountered with Nested Angular Material Tabs

Is there a way to prevent changes made to the upper tab in md-align-tabs attribute from affecting the inner tab when one tab is nested inside another using md-tabs? If so, how can I achieve this? <md-content layout="column" layout-fill> <md-ta ...

Animating ng-switch transitions within a div element

Utilizing bootstrap 3 panel along with ng-switch for a sliding animation: Check out the Plunker here I am facing an issue where the animation extends past the borders of the panel instead of staying within it. How can I fix this in my Plunker? The desire ...

Obtain the Upload URL using an Angular service

I am currently working on an Angular project that uses Dropzone.js as the drag-and-drop file upload component. The challenge I'm facing is that Azure requires a unique URL to be generated for each file upload. Dropzone.js has a "url" config option th ...

I am attempting to swap values within table cells using AngularJS. Would it be recommended to utilize ngBind or ngModel, or is there another approach that would

How can I make a table cell clickable in AngularJS to switch the contents from one cell to another, creating a basic chess game? I want to use angular.element to access the clicked elements and set the second clicked square equal to the first clicked using ...

verified that all form checkboxes were selected in angularJS

Hey there, I have a form in AngularJS with multiple checkboxes. When the first checkbox (Check All) is clicked, I want all the checkboxes to be checked. How can I achieve this using Angular for each field loop? Below is a snippet of my code: vm.asas = f ...

Identifying Whether Angular ng-repeat is Displaying Output or Not

I am trying to display a "No result" message when the search field does not have any matches. The current filter is working fine, but it does not show the message when there are no results. How can I achieve this? <div class="portfolio-list-wrap" ng-co ...

Dokku displays previous version of the site following deployment

My university has a dokku server that I manage. Despite making changes to the website, such as adding buttons and deploying successfully to Dokku, the old build continues to display. I have attempted redeploying and even rebooted the server entirely, yet ...

The AngularJS Factory $http encounters an error when attempting to read the property 'length' of an undefined value

I am looking to implement a factory in my REST Controller that will return an array of Strings. I want to be able to reuse this function in my services.js file. Here is the HTML for an Autocomplete input field: <input type="text" ng-model="vertrag.ver ...

Can you explain the significance of the syntax "require: ^"?

Can someone explain the significance of the ^ symbol under require in this Angular directive code snippet? I came across this code and am having trouble understanding its meaning. .directive('accordionGroupHeading', function() { return { ...

In Angular, the `Get` function will return an array, not an object

I am currently facing an issue where I am trying to retrieve a single user instead of receiving an entire list of users. The query is functioning properly, however, the Get method is not working as expected. Could this be due to the fact that the user cont ...