What is the best way to send an ID to my ui-view component?

I am trying to access inventory items by their ID using the link /inventory/description/:{{id}}. However, I am facing some issues with it as nothing is showing up. How can I successfully access these items by ID?

app.config(function config( $stateProvider, $urlRouterProvider) {
  $stateProvider.state('inventory',{
    url:'/inventory',
        views: {
            "main": {
                controller: 'InventoryCtrl',
                templateUrl: 'inventory/main.tpl.html'
            }
        },
        data:{ pageTitle: 'Inventory' }
  }
  ).state('inventory.detailview',{
    url:'/inventory/detailview',
        views: {
            "detailview": {
                controller: 'InventoryCtrl',
                templateUrl: 'inventory/detail.tpl.html'
            }
        },
        data:{ pageTitle: 'DetailView' }
  }
  ).state('inventory.description',{
    url:'/inventory/description/:{{id}}',
        views: {
            "descriptionview": {
                templateUrl: 'inventory/description.tpl.html',
                controller: function($scope, Inventory){
                    $scope.id = Inventory.query('id');

            }}
        },
        data:{ pageTitle: 'DescriptionView'}
  });
});

This is my factory:

app.factory('Inventory', function($resource, $http) {
return $resource('http://web.lv/api/v1/inventory/:id', {id: "@id"},
    {
        update: {
            method: 'POST',
            params: {id: '@id'},
            isArray: false
        },
        save: {
            method: 'PUT'
        },
        query: {
            method: 'GET',
            params: {id: '@id'},
            isArray: false
        },
        create: {
            method: 'POST'
        },
        drop: {
            method: 'DELETE',
            params: {id: "@id"}
        }
    }
);
});

And this is my controller:

app.controller('InventoryCtrl', function($scope, $http,  Inventory, $location) {    

    // Getting the objects from Inventory
        $scope.info = Inventory.query();

    // 
        $scope.id = Inventory.query('id');

}

Answer №1

In the case that ui-router is being utilized, the stateParams feature can be employed.

app.controller('InventoryCtrl', function($scope,$stateParams,Inventory) { 
     $scope.itemID = $stateParams.itemID;
}

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

Having trouble getting my node.js and socket.io code to function properly

This is my code for basic broadcasting functionality on the server side: Server Side var socket = require( 'socket.io' ); var express = require( 'express' ); var http = require( 'http' ); var app = express(); var server = h ...

What sets the target property of the mousewheel event apart from other events like click, mousedown, and touchstart?

The mousewheel event's target property reveals the DOM element currently being hovered over when using the mousewheel or gesture-capable touchpad. In my experience (specifically in Safari 6, I will verify this in other browsers later), the target ret ...

Creating an error handler in PHP for dynamically adding or removing input fields is a crucial step in ensuring smooth and

I designed a form with multiple fields, including a basic input text field and dynamic add/remove input fields. I successfully set the first field as required using PHP arguments, but I'm struggling to do the same for the additional fields. I need as ...

Confirming an authorization?

I have been working on this code and it is almost perfect, but I am struggling to understand why it needs to validate the 0 or 10 in order to work correctly. The issue I am facing is with a validation where the button should be deactivated when the counte ...

Encountering an "Unmet Peer Dependency" error message while attempting to integrate bootstrap-ui into my Angular project

Currently, my goal is to successfully install angular-ui. Following the tutorials, I have attempted all commands such as: npm install angular-bootstrap However, this command results in an error message: +-- UNMET PEER DEPENDENCY angular@>=1.5 After ...

Unable to locate a contact within the state

Currently, I am diving into the world of React by exploring its documentation and challenging myself to build a small chat application. While I have a good grasp on the basics, I am encountering some issues with states. Within my code, there is an object ...

What steps should I follow to generate a JSON object and apply it to refresh an ng-repeat?

Struggling to work this out. I am aiming to craft a JSON object and then utilize it to enhance my ng-repeat (specifically, prepend the ng-repeat with the information contained in the JSON object). Presented below is my code: Javascript: var data1 = &apos ...

Add buttons to images to provide further explanations

While browsing the Excel Learn website, I came across a picture that displayed buttons explaining various functions in Excel. By clicking on the picture, a menu would open up to further explain the corresponding button. If you want to see this in action, ...

Important notice: Warning for stand-alone React 18 page regarding the import of createRoot from "react-dom"

I am in the process of developing a standalone webpage utilizing React 18: <!DOCTYPE html> <html lang="en"> <head> <title>Hello React!</title> <script crossorigin src="https://unpkg.com/react@1 ...

Typescript error encountered when executing multiple API calls in a loop causing Internal Server Error

I'm relatively new to Typescript/Javascript and I am working on a function called setBias(). In this function, I want to set all indices of this.articles[i].result equal to the biased rating returned by the function getBiasedRating(this.articles[i].ur ...

Error message thrown by Angular JS: [$injector:modulerr] – error was not caught

I have been working on a weather forecasting web application using AngularJS. Here's a snippet of my code: var myApp = angular.module("myApp", ["ngRoute", "ngResource"]); myApp.config(function($routeProvider){ $routeProvider .when('/',{ ...

Identifying whether a child component is enclosed within a specific parent using React

Is there a more elegant and efficient method to determine if the parent of SeminarCard is Slider? Currently, I am passing this information through a prop. The prop value (true/false) is used to provide additional padding. When used independently: <Semi ...

The "util" module has been extracted to ensure compatibility with browsers. Trying to use "util.promisify" in client code is not possible

Currently, I'm in the process of scraping LinkedIn profiles with the help of this library: https://www.npmjs.com/package/@n-h-n/linkedin-profile-scraper. Listed below is the code snippet that I am using: <script> import { LinkedInProfileScraper ...

Tips for combining values from two inputs to an angular ng-model in AngularJS

I am working with an angular application and I am trying to figure out how to combine values from multiple inputs into one ng-model. Here is an example of my current input: <input type="text" class="form-control input-md" name="type" ng-model="flat.f ...

Swapping out 'useResult' in graphql for Vue and Apollo: A step-by-step guide

I need to replace the useResult function that is fetching data from GraphQL with a computed function. const locationOptions = useResult( result, [], ({ getLocations }): Option[] => formatOptions(getLocations) ) Instead, I want ...

Different techniques for retrieving elements generated by ng-repeat from their containing parent

Let's keep it simple - imagine we have a directive called headSlides. This directive's template includes an image that is being repeated using ng-repeat: <img class="bg" ng-repeat="image in images" ng-src="{{image.src}}"> I need to access ...

Enhance your Ionic 2 application with a versatile barcode scanner featuring multiple fields

Exploring the Barcode Scanner Plugin in Typescript scanBarCode() { this.barcodeScanner.scan().then(barcodeData => { this.scannedbarCode = barcodeData.text; }, (err) => { console.log('Error: ', err ...

Having trouble with implementing both filter and infinite scroll simultaneously in an Ionic list?

I've encountered an issue with my ionic hybrid app related to angularjs filters. The code snippet below showcases the problem: <input type="search" placeholder="Search personalities" ng-model="name" ng-change='alert("changed!")&apo ...

Sequencing numerous promises (managing callbacks)

I am encountering some challenges with promises when it comes to chaining multiple ones. I'm having difficulty distinguishing how to effectively utilize promises and their differences with callbacks. I've noticed that sometimes callbacks are trig ...

Find the specific element that is visible within a customized viewport, such as a div or ul

Exploring the capabilities of the Viewport Selectors for jQuery plugin, here is a snippet of its source code: (function($) { $.belowthefold = function(element, settings) { var fold = $(window).height() + $(window).scrollTop(); return fold <= $ ...