grunt error TS1005: missing semicolon

Currently, I am working with Angular and TypeScript to interact with a REST webservice. Since I am still new to TypeScript, my issue might be basic or my approach could be incorrect. The problem I am facing is receiving an error TS1005: ';' expected when compiling my exampleController.ts using Grunt. I have already researched for a solution but unfortunately, I have not come across anything that has been helpful. In my code, I am already utilizing

import angular = require('angular');
Here is a snippet of my controller code:

class ExampleComponentController {

public static $inject = [
  '$scope',
  'productRestService',
  '$http'
];

$scope.submit = function(form) {

    var config = {
        'username' : $scope.name,
        'password' : $scope.pass
    };

    var $promise = $http.post('requat_url', config)
        .success(function(data, status, headers, config) {
            ...
        })
        .error(function(data, status, headers, config) {
            ...
        });
}; 

constructor(...) {...} 
}

The error occurs on the line where $scope.submit is defined. Any advice would be greatly appreciated.

Answer №1

To ensure proper functionality, the $scope.submit... code snippet should be located within the constructor. Additionally, the constructor parameters must align with the elements listed in the $inject array:

class ExampleComponentController {
  public static $inject = [
    '$scope',
    'productRestService',
    '$http'
  ];

  constructor($scope, productRestService, $http) {
    $scope.submit = function (form) {

      var config = {
        'username': $scope.name,
        'password': $scope.pass
      };

      var $promise = $http.post('requat_url', config)
        .success(function (data, status, headers, config) {
        })
        .error(function (data, status, headers, config) {
        });
    };
  }
}

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

Is there a way to create numerous div elements in real-time when a click event occurs?

I've created a web application that requires the user to input a product number. Adjacent to the input field is an arrow icon that the user clicks. Upon clicking, there is validation to ensure that the entered number matches one of the valid product n ...

Exploring the benefits of leveraging TypeScript with AWS NodeJS for improved stacktrace visibility over traditional JavaScript

I'm contemplating the idea of transitioning my existing JavaScript codebase to incorporate TypeScript in NodeJS. One aspect that I am concerned about is being able to view the stack trace in AWS CloudWatch (request log) in case an error occurs during ...

"Render Failure" JavaScript and CSS files

I'm encountering a peculiar issue while attempting to load certain JS and CSS files. Within my ASP.NET MVC Web Project, I have an Index.html file where I've specified the loading of script files. It's worth noting that I have modified the U ...

Is there a way to operate both websocket and http methods concurrently on a server in Typescript?

I have a question regarding running a websocket server with the route "ws://localhost:port" using the 'ws' library. It requires the app instance of 'express' and also features http routes such as "http://localhost:port/auth/login". I am ...

How can I manage the transfer of items between lists in angular-ui sortable?

I am currently utilizing angular-ui sortable version 1.2 My goal is to manage the transfer of an item from one list to another and ensure that the back-end gets updated accordingly. The jquery-ui-sortable plugin offers various events, such as the receive ...

What is the best method to retrieve a JSON record by its specific ID using Angular's AJAX functionalities?

I've been working on a function within my service that retrieves data function getSomeData() { return $http .get('/someData.json') .then(itWorked) .catch(onFail); Currently, this function returns all the records from the J ...

When trying to use `slug.current` in the link href(`/product/${slug.current}`), it seems to be undefined. However, when I try to log it to the console, it is displaying correctly

import React from 'react'; import Link from 'next/link'; import { urlFor } from '../lib/clients'; const Product = ({ product: { image, name, slug, price } }) => { return ( <div> <Link href={`/product/ ...

typescript scrolling location

In my Angular UI code, I have a component class that includes the following structure: app.component.html //... <div class="banner"> <p-dialog [(visible)]="displayCOI" styleClass="coiDialog" [contentStyle]=" ...

React and Redux - "Plain objects are required for actions"

I can't seem to understand why this is not functioning properly. Currently, I am working with React and Redux in Typescript. This is the code snippet: import * as React from 'react'; import * as ReactDOM from 'react-dom'; import ...

Tips on invoking a child component's function from the parent component

I'm struggling to comprehend, Is there a way to trigger a function within a child component by clicking on a button in the parent component? ...

Looking to implement a feature in Angular 2 where content on a page can be filtered based on a single array property of the user

Feeling lost here. I need to filter books on the page by their specific Category (Philosophy, Classic, Poetry, etc.) when a user clicks a corresponding button. However, I'm new to Angular and coding in general, so I really want to grasp this concept f ...

Mastering the Art of Utilizing AngularJS to Harness the Power of Keypress and

Currently, I am in the process of developing a calculator utilizing AngularJS. The issue arises when clicking on the '923216' buttons triggers the "updateOutput(btn)" function, successfully appending them and updating the view. However, upon addi ...

allowChoosing and uiGridEnums

I'm attempting to make rows selectable based on a specific $treeLevel value. When I ran the code, I encountered a ReferenceError: uiGridConstants is not defined. I must confess that I am uncertain about the purpose of uiGridConstants. Below is the c ...

There seems to be a malfunction with the hide and reset features, as they are

I have encountered an issue while working on hiding a series in Google Charts when clicked on the legend. The problem arises when an extra column is added to display tooltips on the bars, causing the functionality to break. Please check out the demos below ...

Obtain non-numeric parameters from the URL in Angular 2 by subscribing to

How do I handle subscribing to a non-numeric parameter from a URL? Can the local variable inside my lambda function params => {} only be a number? Here's my code: getRecordDetail() { this.sub = this.activatedRoute.params.subscribe( ...

Angular directives enable the addition of DOM elements using ng functions

I'm currently working on creating a custom directive for a small input field that only accepts text. The goal is to dynamically change an icon from a search glass to an X if there is text in the input field, and clear the text when it is clicked on. I ...

A guide on utilizing server-based data grouping and showcasing it in ag-grid within an angular environment

Is there a way to organize the data based on the server name, which is identified by the object key server? The code snippet below illustrates the structure of the data: rowData = [ { server: "Server 1", ping: "10 ms", ...

Utilizing the Literal Form of a Generic Object Parameter

I'm looking for a way to modify the return type of a function that accepts a generic object. I want the return type to be identical to the object passed in, but narrowed down similar to how `as const` assertions work. For example, if I call the funct ...

What is the recommended approach for sending a null value to a mandatory property in a Vue.js component?

Setup: Vue.js (3.2) with Composition API, TypeScript, and Visual Studio Code File type.ts: export class GeographicCoordinate { latitude: number; longitude: number; altitude?: number; constructor(latitude: number, longitude: number, altitude?: num ...

In React Native, a scenario occurs where multiple records are added to an array after the second object is pushed onto it

Having an issue with React Native where, when trying to check if an object is present in an array and then replacing it with a new one, a strange behavior occurs: after inserting the 2nd object, the 3rd object gets pushed twice, the 4th object 4 times. I ...