The issue of elements not appearing seems to be related to the passing of parameters to the state

In my AngularJS application, I have a form where users must input an application number. Upon successful entry, the corresponding data should be displayed below. This data can only be accessed through the scope if passed as a parameter to the current state. I am utilizing ui-router for routing.

While browsing discussions like Reloading current state - refresh data, I learned that passing data to the current state without refreshing the page is possible. However, despite implementing this solution, my content fails to show up. Additionally, I'm uncertain about the proper usage of ng-show and/or ng-if. Here is the function responsible for passing the data:

vm.findPatent = function(patentNo) {
    searchPatentService.findPatent(patentNo)
    .then(
        function(data) {
            $state.go('.', { patent: data }, {reload: false, notify: false, location: false})
            })
        },
        function(errResponse) {
            console.error('Error while finding patent');
        }
    );
}

The parameters within the state are defined as follows:

.state('search-patent', {
    url: '/search-patent',
    component: 'searchpatent',
    params: {
        navigation: 'patentnav',
        patent: null
    }
})

Below is the view with the form that triggers the display of content upon submission:

<form ng-submit="$ctrl.findPatent(searchPatent)" name="searchPatentForm">
    <fieldset>
        <div class="form-group row">
            <label for="searchPatent">EP No.</label>
            <div>
                <input type="text" name="searchPatent" ng-model="searchPatent" class="form-control" placeholder="Search" required>
            </div>
        <div>
            <button type="submit">Submit</button>
        </div>
    </div>
  </fieldset>
</form> 

<div class="row" ng-show="searchPatentForm.$submitted">
    <div class="col-md-12">
//ANOTHER FORM AND CONTENT WHICH IS DISPLAYED ON SUBMIT
    </div>
</div>

Query

I need assistance in passing data to the current state without causing a page refresh. Furthermore, any suggestions for improving the use of ng-show would be greatly appreciated. Thank you!

Answer №1

After submitting, you may want to stay on the page.

$scope.result= null;
vm.findPatent = function(patentNo) {
    searchPatentService.findPatent(patentNo)
    .then(
        function(data) {
            $scope.result=data;
            })
        },
        function(errResponse) {
            console.error('Error while finding patent');
        }
    );
}

If you wish to keep the div on the page after submission, consider using ng-if; otherwise, try using ng-show. For more information, visit this link.

<div class="row" ng-if="result">
    <div class="col-md-12">
      {{result}}
    </div>
</div>

To see a detailed example, check out this site

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

Carousel position images off-center to the right on smaller screens

I created a fullscreen slider using the carousel bootstrap feature. However, when the screen size shrinks, the background image resizes and centers itself. Instead of centering the image on smaller screens, I want it to focus on the right side. Here is ho ...

Connection error: API is down

The current issue I am facing with the application I'm developing is that it is not responding with the API address for weather data. Despite getting a response from Ajax, the specific weather API I am trying to call remains unresponsive. I have exha ...

What is the best way to highlight specific text in React components that is passed from an object?

This is the page HTML content where an object is created. A portion of the description needs to be emphasized: const agencyProps = { title: "Managed agency selection", paragraph: "Strengten your onboarding process", videoImage: { ...

Establish the starting time for the timer and use the setInterval() function according to the seconds stored within the object

How can I configure the values of timerOn, timerTime, and timerStart to make the watch start counting from 120 seconds? Currently, the clock starts counting from 3 minutes and 22 seconds, but it should start from 2 minutes. You can find all the code here: ...

Removing the Angular controller instance

To make things easier, the issue has been condensed under "The problem" for quick reference. For more details, continue reading for background information and notes before providing an answer. Thank you! The problem My goal is to remove the instance of a ...

Managing websites on Android when the keyboard is displayed

I am currently facing an issue with my webpage on Android (Galaxy SIII). The problem occurs when visitors try to enter their email in the form at the bottom of the page. The keyboard becomes visible, causing the design to look messy. When using Chrome, the ...

Fetching a collection from Cloud Firestore using Angular and Firebase

I'm looking to figure out how to retrieve lists from cloud firestore. Here is how I upload a list : export interface Data { name: string; address: string; address2: string; pscode: string; ccode: string; name2: string; } constructor(pri ...

Steps for resolving the error message: "An appropriate loader is required to handle this file type, but there are no loaders currently configured to process it."

I am encountering an issue when working with next.js and trying to export a type in a file called index.ts within a third-party package. Module parse failed: Unexpected token (23:7) You may need an appropriate loader to handle this file type, current ...

Utilize the Bootstrap column push-pull feature on the mobile version of

https://i.stack.imgur.com/yTBIt.png When viewing the desktop version, div A is displayed at the top of the page. However, I would like to move it to the bottom when viewing on a mobile device (col-xs). I have attempted to solve this issue myself without s ...

Error in Vue.js and Socket.io - the server response cannot contain the wildcard '*' when the request has its credentials mode set to 'include'

I'm currently working on creating a chat app using Vue and Socket IO. Here's the error I'm encountering. This is my Node server code. And this is my Vue app code. My Node server and Vue app are separate entities. How can I resolve this i ...

What is preventing me from filling my array with the URL inputted by the user?

I am looking to dynamically populate an array with URLs and display them one by one as users upload files. The goal is for each user to upload a file, have it stored in the array, and then displayed on the page. Specifically, I want to generate <img/&g ...

What's the best way to constrain a draggable element within the boundaries of its parent using right and bottom values?

I am currently working on creating a draggable map. I have successfully limited the draggable child for the left and top sides, but I am struggling to do the same for the right and bottom sides. How can I restrict the movement of a draggable child based o ...

Do I need to include a callback in my AWS Lambda handler function?

What is the function of the callback in the lambda handler? It appears to be utilizing the sns variable and I am looking to make some modifications to the variables. exports.handler = function(event, context, callback) { console.log("AWS lambda and ...

Error: Surprising token found in ReactJS application on CodeSandbox

Encountering an unexpected token on line 5 error in my ReactJS project when testing it on CodeSandbox. Interestingly, the app runs smoothly without errors on my local machine. import React, { Component } from 'react'; import Header from ' ...

Retrieving information from JSON files related to table objects

How to Display JSON data in a Table? I am facing difficulty accessing my JSON data as it is nested within an array of objects. How can I retrieve this information? Currently, I am using the map function to display only the name and avatar, but the data s ...

Issue with Backbone.Marionette: jQuery document.ready not executing when on a specific route

I am dealing with a situation in my web application where the document.ready() block is not being executed when the page routes from the login button to the dashboard. I have an initialize() function that contains this block, but it seems like there is an ...

What is the process for fixing the top header row to display column titles in a bootstrap-vue table?

I am currently using a bootstrap-vue table with the following structure; https://i.sstatic.net/5sv6R.png Below is the code snippet for reference; <template> <div> <b-table hover :items="items"></b-table> </div ...

Steps for integrating a controller with ui-router in AngularJS:

Seeking assistance with setting up ui-router in AngularJS for the first time. I suspect my script.js file may be incorrect. Any guidance would be greatly appreciated. Could the issue be related to the app.controller? Where did I make a mistake? var app = ...

Support for h264 in Windows Media Player across various versions of Windows operating system

Are there specific versions of Windows that are capable of playing h264 videos with Windows Media Player installed by default? Is it feasible to determine this support using Javascript? We currently deliver MPEG-4 video files through Flash, but some users ...

Maintain the original order of rows in the table while shuffling the columns they appear in randomly

I need help with my table setup. The left column contains words in English, while the right column has the same words translated into Korean. Is there a way to keep the rows intact while randomizing the order of the columns? Here's an example: <ta ...