Searching for a location path with parameters does not lead to navigation to the next page

I am trying to pass a parameter to the next page (edit page) by clicking on an edit button. The code I have tried is not working as expected. When I click on the button, the URL is displayed correctly but the page shows up blank and the controller does not load. Can you help me identify what is causing this issue?

http://localhost:8080/#/group/edit?id=586351373b6bba91152ab744

View

<md-button class="md-raised md-primary" ng-click="doEdit(item._id)" title="Edit">Edit</md-button>

Route

$routeProvider.when('/group/edit', {
      templateUrl: 'template/group_edit.html',
      controller: 'GroupEditCtrl'
})

Controller

$scope.doEdit = function (id) {
    $location.path('/group/edit').search({id: id});
}

Answer №1

It might be beneficial to include more code to pinpoint the issue, as this basic snippet appears to be functioning correctly.

angular.module('MyApp', ['ngMaterial', 'ngRoute']);

angular
  .module('MyApp')
  .config(['$routeProvider', setupRoutes])
  .controller('ViewController', ['$scope', '$location', ViewController])
  .controller('GroupEditController', ['$scope', '$location', GroupEditController]);

function setupRoutes($routeProvider) {
  $routeProvider.
        when("/view", { controller: "ViewController", templateUrl: "view.html" });
  $routeProvider.when('/group/edit', {
      templateUrl: 'edit.html',
      controller: 'GroupEditController'
  })
}

function ViewController($scope, $location) {
  $scope.item = {_id: 123}
  $scope.doEdit = function (id) {
    $location.path('/group/edit').search({id: id});
  }
}

function GroupEditController($scope, $location) {
  $scope.locationParam = $location.search().id
  $scope.goBack = function() {
    $location.path('/');
    }
}
<html lang="en" >
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- Angular Material style sheet -->
  <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/angular_material/1.1.0/angular-material.min.css">
  
</head>
<body ng-app="MyApp" ng-cloak>
  
  <ng-view></ng-view>
 
  <script type="text/ng-template" id="view.html">
    <md-button class="md-raised md-primary" ng-click="doEdit(item._id)" title="Edit">Edit</md-button>
</script>
  
  <script type="text/ng-template" id="edit.html">
    hey edit! ID: <pre>{{locationParam | json}}</pre> <br/>
    <md-button class="md-raised md-primary" ng-click="goBack()" title="Back">Back</md-button>
</script>
  
  
  
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-route.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-animate.min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-aria.min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-messages.min.js"></script>

  <!-- Angular Material Library -->
  <script src="https://ajax.googleapis.com/ajax/libs/angular_material/1.1.0/angular-material.min.js"></script>
  
  
  
</body>
</html>

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

Issues with cross-browser compatibility are arising in my jQuery code

Here is the code snippet I'm working with: function toggleLoader( display ){ if( display === 'show' ){ $('.overlay, .loader').css({ 'z-index' : '1000', 'display& ...

Integrate a @Component from Angular 2 into the Document Object Model of another component

One of my components is called TestPage import { Component } from '@angular/core'; @Component({ selector: 'test-component', template: '<b>Content</b>', }) export class TestPage { constructor() {} } Another ...

Tips for incorporating a multiple tag search feature within my image collection using JavaScript?

I am facing a challenge with my image gallery search feature. Currently, users can search for images by typing in the title or tag of an image. However, I need to enhance this functionality to allow for multiple tags to be searched at once. For example, if ...

Including a personalized User-Agent string in my headers for fetch requests

Currently, I am utilizing the fetch API within my React project to retrieve data from a JSON endpoint. One requirement I have is to include a custom User-Agent string in my requests. Upon inspecting my requests, I noticed that the UA string displays as: ...

Error encountered when trying to import Typescript file using a relative path

When attempting to execute src/index.js, I encountered the following error: Error: Cannot find module './utils/spinner' The import statement in index.js appears as follows: const { startSpinner, stopSpinner } = require('./utils/spinner&apos ...

Styling the background of the endAdornment in a material-ui textfield using React

I tried following the instructions from this source: Unfortunately, the example code provided doesn't seem to be functioning properly now. Is there a way to achieve the same result without having that right margin so that it aligns better with the r ...

External function does not support jQuery types

In my theme.js file, I currently have the following code: jQuery(function ($) { accordion($) }) const accordion = ($) => ... By placing the accordion function directly into the jQuery function, Typescript is able to assist with the installed jquery ...

Encountered a Uncaught TypeError: Attempted to clear a canvas when the property 'getContext' is undefined or null

After researching multiple error solutions, none seemed to work for me. It became frustrating, leading me to consider spamming just to bypass the word limit and share my own findings with others facing similar issues. Check out the Answers section below to ...

What is the best way to establish a global database connection in express 4 router using express.Router()?

Is there a way to pass a global variable in Node.js from a file to a module? I have been attempting to do so with a 'db' variable that represents a MongoDB connection. I tried copying the content of my file for the connections, but it didn't ...

Utilizing Fullcalendar to Show Multiple Months

Is there a way to display two months side by side using the FullCalendar plugin? I have not been able to find a solution in other similar questions. Here is my current setup: <div class="calendar-box"> <div clas ...

When you press the back button and navigate to a different page, the scroll position will remain unchanged

I'm facing an issue with scrolling on my angularjs app. Currently, the app consists of 2 pages: The first page displays a list of customers, where you can select one to view their details. The second page is a list of companies, following a similar s ...

Using Javascript to determine if a DropDown list is currently disabled

This code snippet checks whether the DropDownList is disabled or not. function CheckRowBeforeSaving() { for (i = 0; i < document.forms[0].length; i++) { if (e.id.indexOf("_ddlTask") != -1) { var disabled = e.disabled; alert(d ...

Tips for creating a Carousel with more than three images using Bootstrap

Recently, I attempted to enhance my Carousel in Bootstrap by adding more images. Initially, I inserted the code snippet below within the ordered list with the class "carousel-indicators." <li data-target="#carouselExampleCaptions" data-slide-to=" ...

Updating bindings in AngularJS from promisesIn AngularJS, promises do not automatically update

I've encountered an issue with my promise implementation. After the promise resolves, the view doesn't update with the new value. Here's a small example in jsfiddle to demonstrate the problem: http://jsfiddle.net/58q8khap/8/ This is the vi ...

Attempting to locate an element within the DOM using TypeScript

I am completely new to TypeScript. I have been attempting to locate an element using a selector, but no matter what I tried, the findElement() method always returns undefined. Can someone please point out where my mistake might be? Any assistance would b ...

I want to know how to keep additional inline whitespace while using the default JS/TS formatter in VS Code

Take this line, for example: var x = 5; var yyyyy = 10; var zzzzzz = 15; The VS Code Formatter removes the extra spaces between variable names and values. var x = 5; var yyyyy = 10; var zzzzzz = 15; Is there a way to configure it to keep the f ...

Click event handling in child components with Vue 2

I have a basic component with the following structure: <template> <span @click="clickHandler" :class="className"></span> </template> <script> export default { name: "PlusIconComponent", props: { ...

Updating Information Using JQuery

In my view, there is a partial view that displays details of open IT Tickets. Clicking on an open ticket loads the partial view with ticket details and comments using JQuery/Ajax. However, I'm facing an issue where if a new comment is added to a tick ...

Guide to accessing object items in v-for in VueJs

Upon inspection, the following results are being displayed: https://i.sstatic.net/oF4Qe.png https://i.sstatic.net/21aHB.png In the Vue template code provided: <select class="form-select" v-model="post_format.wpml_language"> <option v-for="(l ...

JavaScript function for exporting HTML table to Excel with the ability to choose the file name

My current challenge involves a function used to export HTML to Excel: function generateexcel(tableid) { var table= document.getElementById(tableid); var html = table.outerHTML; window.open('data:application/vnd.ms-excel,' + encodeURICompo ...