The type 'Data' is lacking the following attributes from its definition

Being a newcomer to Angular 8, I can't figure out why this error is popping up. If you have any suggestions on how to improve the code below, please feel free to share your tips.

The error message reads: Type 'Data' is missing the following properties from type 'Documentary': id, title, slug, storyline, and 13 more.

The issue lies within AdminDocumentaryEditComponent

 ngOnInit() {
      this.route.data.subscribe(data => {
        this.documentary = data; //here
        console.log(this.documentary);
        this.initForm();
      })
    }
  

DataService

import { HttpClient, HttpParams } from '@angular/common/http';
    import { Injectable } from '@angular/core';
    import { throwError } from 'rxjs';
    import { catchError } from 'rxjs/operators';

    @Injectable({
      providedIn: 'root'
    })
    export class DataService {
      constructor(private url: string, private http: HttpClient) { }

      get(slug) {
        return this.http.get(this.url + '/' + slug);
      }

      getAll(params:HttpParams) {
        return this.http.get<Object[]>(this.url, 
        {
          params: params
        });
      }

      create(resource) {
        return this.http.post(this.url, JSON.stringify(resource));
      }

      update(resource) {
        return this.http.put(this.url + '/' + resource.id, JSON.stringify({

        }));
      }

      delete(id: number) {
        return this.http.delete(this.url + '/' + id);
      }
    }
  

DocumentaryService

import { HttpClient } from '@angular/common/http';
    import { DataService } from './data.service';
    import { Injectable } from '@angular/core';

    @Injectable({
      providedIn: 'root'
    })
    export class DocumentaryService extends DataService {

      constructor(http: HttpClient) {
        super('http://localhost:8000/api/v1/documentary', http);
      }
    }
  

DocumentaryResolverService

import { Documentary } from './../models/documentary.model';
    import { DocumentaryService } from './documentary.service';
    import { Injectable } from '@angular/core';
    import {
      Resolve,
      ActivatedRouteSnapshot,
      RouterStateSnapshot
    } from '@angular/router';

    @Injectable({ providedIn: 'root' })
    export class DocumentaryResolverService implements Resolve<Documentary> {
      constructor(private documentaryService: DocumentaryService) {}

      resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
        let slug = route.params['slug'];
        let documentary = this.documentaryService.get(slug)[0];
        return Object.assign(new Documentary(), documentary);
      }
    }
  

AdminDocumentaryEditComponent

import { Documentary } from './../../../models/documentary.model';
    import { DocumentaryService } from './../../../services/documentary.service';
    import { Params, ActivatedRoute, Router } from '@angular/router';
    import { Component, OnInit, ViewChild, ChangeDetectorRef } from '@angular/core';
    import { FormArray, FormControl, FormGroup, Validators } from '@angular/forms';
    import { AngularEditorConfig } from '@kolkov/angular-editor';

    @Component({
      selector: 'app-admin-documentary-edit',
      templateUrl: './admin-documentary-edit.component.html',
      styleUrls: ['./admin-documentary-edit.component.css']
    })
    export class AdminDocumentaryEditComponent implements OnInit {
      documentary: Documentary;
      editDocumentaryForm: FormGroup;

      constructor(
        private route: ActivatedRoute,
        private documentaryService: DocumentaryService,
        private router: Router,
        private cd: ChangeDetectorRef) {}

      editorConfig: AngularEditorConfig = {
        editable: true,
        spellcheck: true,
        height: '25rem',
        minHeight: '5rem',
        placeholder: 'Enter text here...',
        translate: 'no',
        uploadUrl: 'v1/images', // if needed
      };

      ngOnInit() {
        this.route.data.subscribe(data => {
          this.documentary = data;
          console.log(this.documentary);
          this.initForm();
        })
      }

      initForm() {
        let title = this.documentary.title;
        let slug = this.documentary.slug;
        let storyline = this.documentary.storyline;
        let summary = this.documentary.summary;
        let year = this.documentary.year;
        let length = this.documentary.length;
        let status = this.documentary.status;
        let short_url = this.documentary.short_url;
        let poster = this.documentary.poster;

        this.editDocumentaryForm = new FormGroup({
          'title': new FormControl(title, [Validators.required]),
          'slug': new FormControl(slug, [Validators.required]),
          'storyline': new FormControl(storyline, [Validators.required]),
          'summary': new FormControl(summary, [Validators.required]),
          'year': new FormControl(year, [Validators.required]),
          'length': new FormControl(length, [Validators.required]),
          'status': new FormControl(status, [Validators.required]),
          'short_url': new FormControl(short_url, [Validators.required]),
          'poster': new FormControl(poster, [Validators.required])
        });

        this.editDocumentaryForm.statusChanges.subscribe(
          (status) => console.log(status)
        );
      }

      onFileChange(event) {
        let reader = new FileReader();

        if(event.target.files && event.target.files.length) {
          const [file] = event.target.files;
          reader.readAsDataURL(file);

          reader.onload = () => {
            this.editDocumentaryForm.patchValue({
              poster: reader.result
            });

            // need to run CD since file load runs outside of zone
            this.cd.markForCheck();
          };
        }
      }

      onSubmit() {
        console.log(this.editDocumentaryForm);
      }
    }
  

Answer №1

When setting up routing, it is important to ensure that the resolver is named 'data' as shown below:

 { path: 'somepath', component: AdminDocumentaryEditComponent, resolve: { data: DocumentaryResolverService} }

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

Invalid JSON due to escaped HTML characters

After using a tool to escape all characters in my JSON containing HTML code, I encountered an issue when trying to validate it. The error message received was: Parse error on line 2: { "html": "<table class=\"MsoT -----------^ Expecting &apos ...

I am seeking to modify the CSS of the parent component upon the loading of the child component in Angular

In my Angular blog, I have a root component with a navigation bar containing router links to create a single-page application. My goal is to darken the background around the link when the child component loads. Currently, the link highlights only when pres ...

What methods are most effective when utilizing imports to bring in components?

Efficiency in Component Imports --Today, let's delve into the topic of efficiency when importing components. Let's compare 2 methods of importing components: Method 1: import { Accordion, Button, Modal } from 'react-bootstrap'; Meth ...

Display the new data from an array that has been created following a subscription to Angular Firestore

I am struggling to access the content of a variable that holds an array from a Firebase subscription. The issue I am facing is that I am unable to retrieve or access the value I created within the subscription. It seems like I can only use the created valu ...

Docz: Utilizing Typescript definitions for props rendering beyond just interfaces

We are currently using Docz to document our type definitions. While it works well for interfaces, we've run into an issue where rendering anything other than interfaces as props in Docz components doesn't seem to display properly. I'm seeki ...

Testing the JSONObject Unit Always Returns Null

After staring at this code for what feels like an eternity, I still can't pinpoint the issue. JSONObject jsonResponse = new JSONObject(); jsonResponse.put("JSON", "hi"); String myString = jsonResponse.getString("JSON"); assertEquals("hi", myString); ...

Creating a Higher Order Component with TypeScript using React's useContext API

Looking to convert this .js code snippet into Typescript. import React from 'react'; const FirebaseContext = React.createContext(null) export const withFirebase = Component => props => ( <FirebaseContext.Consumer> {fire ...

Animated CSS side panel

I'm currently working on creating an animation for a side menu. The animation works perfectly when I open the menu, but the problem arises when I try to animate it back closed. Is there a property that allows the animation to play in reverse when the ...

Tips for sending a POST request with JSON data through the Google API client library in Java

Struggling to make a successful post request using the google api client library. This is the current snippet being utilized UrlEncodedContent urlEncodedContent = new UrlEncodedContent(paramMap); //paramMap consists of email and password keypairs HttpR ...

Streamlined method for creating forms and charts within SharePoint

When it comes to creating charts and forms on SharePoint, what is the best approach for maximizing efficiency? Using AngularJS web parts with CRUD operations. Modifying standard forms and integrating charts using JavaScript libraries and CSS. Are there ...

Encountering issues with Angular 4 dynamic routerlinks on server/localhost, while they work perfectly when the routerlink is

My goal is to create a dynamic navigation menu using a navigation menu service and component. To start, I built a prototype of the navigation menu with hardcoded HTML code like this: <nav> <md-list> <md-list-item rout ...

I possess a JSON array object and need to identify and extract the array objects that contain a specific child node

const jsonArray = { "squadName": "Super hero squad", "homeTown": "Metro City", "formed": 2016, "secretBase": "Super tower", "active": true, "members": [ { "name": "Molecule Man", "age": 29, "secretIdent ...

The TypeScript import statement is causing a conflict with the local declaration of 'Snackbar'

I'm having trouble using the Snackbar component from Material UI in my React app that is written in TypeScript. Whenever I try to import the component, I encounter an error message saying: Import declaration conflicts with local declaration of &apos ...

Looking for assistance with parsing C# / .NET 6 into individual objects

I am currently working with the JsonSerializer.Deserialize() method from the System.Text.JSON library in .NET 6. The JSON format is beyond my control. While I have successfully used this method before, the data I'm dealing with now is slightly more ...

When using `type B = A`, B is represented as A. However, if `type B = A | A` is utilized, B appears as 'any'. What causes this change in representation?

import { C } from "https://example.com/type.d.ts"; type D = C | C Playground Upon hovering over D in both the TS Playground and VS Code, it will show as C when declared as type D = C, but display any when declared as type D = C | C. Even if C&a ...

How can you detect when a user clicks outside of a bootstrap modal dialog in Angular?

Is there a way to detect when a user clicks outside of a Bootstrap modal dialog? <!-- EXPANDED MODAL --> <div class="modal fade" id="itinerary" tabindex="-1" role="dialog" aria-labelledby="modal-large-label"> <div class="modal-dial ...

Unable to retrieve the value of a JSON object

I have a JSON Object called contacts that has the following structure: {"email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="337e524158737b5c5c58525b604752475a5c"><email address hidden></a>","phone":"+197969 ...

Verifying User Permissions with Angular 2/4 and API

I am currently in the process of developing an Angular 2/4 application that interacts with an API built in Laravel 5.4. One area I'm seeking guidance on involves checking authentication and permissions on the backend through Angular. I want to verify ...

What is the best way to extract characters from a jsonArray of Characters and save them into an ArrayList?

In my JSON file, I have the following JSON String: {"Q":[0,1,2,3],"q_0":0,"F":[3],"delta":[[0,1],[0,2],[3,2],[0,1]],"segma":[0,1]} I need to extract and store the 'segma' array as an ArrayList of Characters. static ArrayList<Long> Q; ...

Having trouble loading static files in Django Angular framework? Specifically, images stored in the assets folder returning a

In my Angular project, I have an assets/image folder within the src directory where all my images are stored. Various components and child components in my app use these images like <img src"../../../assets/image/test.png">. After building my Angula ...