Issues arise when trying to implement an AngularJS 1.5 component using TypeScript

I recently tried creating an AngularJS 1.5 component using TypeScript, but unfortunately, it's not functioning as expected. The data binding seems to be completely broken. Although I can see the data in my console when the $onInit function fires, none of that data is displayed on the screen. This is my first attempt at TypeScript and I would greatly appreciate any guidance or help to point me in the right direction?

Below is the code for my component:

class Users implements ng.IComponentOptions {
    public bindings: any;
    public controller: any;
    public template: string;
    public templateUrl: string;
    public transclude: boolean;
    public controllerAs: string;

    constructor() {
        this.controller = UsersController;
        this.templateUrl = "Template/Index?feature=users&template=users";
        this.transclude = false;
        this.controllerAs = "vm";
    }
}


class UsersController {
    public name: string;
    public test: string;
    public Users: any[];

    static $inject: string[] = ["$http", "repository.user"];

    constructor(private $http: any, private RepositoryUser: any) {
    }

    public $onInit(): void {
        this.RepositoryUser.getUsers().then((response: any) => {
            this.Users = response.data;
            console.dir(this.Users);
        });
    }

    public setUser(id: number, value: any): void {
        this.Users[this.Users.indexOf(value)] = value;

    }
}

angular.module("app.users").component("users", new Users());

And here is my HTML code:

<div class="row">
    <div class="col-sm-12">
        <ng-form>
            <h2>Users</h2>

            <div ng-repeat="model in vm.Users track by $index" class="row top10">
                <div class="col-sm-8">
                    <a ui-sref="user-details({ id: model.id })"><strong ng-bind="model.name"></strong></a>
                </div>
                <div class="col-sm-4">
                    <button class="btn btn-default" type="button" ng-click="vm.selectedId=model.id">Select</button>
                </div>
            </div>

        </ng-form>
    </div>
</div>

Answer №1

For those looking to create an AngularJS component in TypeScript, I recommend checking out this syntax guide: . Although the post is in French, you can still benefit from reviewing the sample code provided.

If you have any further questions, feel free to reach out!

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

Typescript polymorphism allows for the ability to create various

Take a look at the following code snippet: class Salutation { message: string; constructor(text: string) { this.message = text; } greet() { return "Bonjour, " + this.message; } } class Greetings extends Salutation { ...

Error: Failed to fetch the data from the Firebase database

I have recently added an edit button to my product list, but when I click on it, the form page opens with no data populated. Upon debugging in my product.service.ts file, I noticed that it outputs null when using console.log(p). I believe this is where the ...

Error: Unable to locate metadata for the entity "BusinessApplication"

I have been utilizing TypeORM smoothly for some time, but out of the blue, I encountered this error during an API call: EntityMetadataNotFound: No metadata for "BusinessApplication" was found. at new EntityMetadataNotFoundError (C:\Users\Rob ...

Facing issues with module resolution while attempting to debug in VSCode

I'm currently in the process of debugging a module within our project. However, I've encountered difficulties attaching the debugger on Visual Studio Code since we recently changed the directory structure. Here is my tsconfig: { "compilerOptio ...

Creating customized JavaScript bundles with TypeScript - a beginner's guide

Our ASP.NET MVC application contains a significant amount of JavaScript code. To optimize the amount of unnecessary JS being loaded to the browser, we utilize the BundleConfig.cs file to create multiple bundles. On the View, we implement logic to determin ...

The error in Angular 6 is that the property 'controls' is not available on the type 'AbstractControl'

What happens when we use setvalue in a for loop? Everything seems to be running smoothly, but unfortunately an error is thrown: The property 'controls' is not recognized on the type 'AbstractControl'. In Angular 6, how can we resol ...

Transform a nested AngularJS service into an Angular Observable service

Currently, I am working on migrating AngularJS(pre 1.5) services that use nested calls to a project being rebuilt in Angular(11). The challenge I'm facing is how to rewrite these services using RXJS. I have been searching for resources or detailed ex ...

Unable to access property value following AJAX call

Here is my code snippet: constructor(props: any) { super(props); this.state = { list: [], }; } public componentWillMount() { this.loadData(); } public loadData = () => { axios.get(someURL) .then((response) = ...

Importing from the project root is a common practice in Typescript

My project structure is organized as follows: .dist classes namespace1 module.js public routes index.js app.js config.js src classes namespace1 module.ts public routes index.ts app.ts config.ts The .dist f ...

Tips to avoid multiple HTTP requests being sent simultaneously

I have a collection of objects that requires triggering asynchronous requests for each object. However, I want to limit the number of simultaneous requests running at once. Additionally, it would be beneficial to have a single point of synchronization afte ...

Validating environment variable values in an AWS CDK TypeScript project

I am facing a problem where I need to include the deployment_env tag with values of either dev, test, or prod on all resources deployed to AWS within a CDK stack. All resources should have identical properties, except for this one tag. I attempted to uti ...

What could be causing the HTTP PUT requests to stop functioning properly after a number of requests?

Currently, I am developing an app for the premier league that allows users to create their own teams, input scores for matches, and view updated team statistics in a sortable table based on the Premier League rules. Issue: I have encountered a problem wi ...

Guide on showcasing file content in a modal popup within a Kendo Grid

Currently, I am facing an issue with displaying the content of a JSON file within a modal window. All I can manage to do is display the file name as a link, but what I really want is to display the actual content of the file. Do you have any ideas on how ...

Leverage GitHub cloning to create my personal project

I'm a beginner when it comes to GitHub. I was wondering if it's feasible to take an entire code from GitHub and customize it to create a different product with unique design and added functionality. The specific link I am referring to is https:// ...

Bring in an Angular Component into a different Component by stating the name of the component as an input parameter

In my project, I am looking to develop an angle component made up of multiple sub-components. The end goal is to construct a versatile tree component with nodes that cater to different data types. Each data type in the tree component will import specific s ...

Utilizing Sequelize with Typescript for referential integrity constraints

After defining these two Sequelize models: export class Users extends Model<Users> { @HasMany(() => UserRoles) @Column({ primaryKey: true, allowNull: false, unique: true }) UserId: string; @Column({ allowNull: false, unique: tru ...

Connect a controller in AngularJS to a service property

I've been encountering an issue with updating my value in the controller. Initially, it works fine with the property value but fails to update later on. Despite trying various methods and going through multiple threads, I can't seem to get it to ...

Tips for managing variations in the naming conventions of JSON fields in request bodies when transferring data from JavaScript to Python using Django REST framework (DRF)

As I work on creating Rest APIs in Python DRF and consuming them in angularJS, I am encountering a challenge related to the naming conventions of variables in JavaScript and Python. JavaScript typically uses camel case for variable names, while Python fol ...

Transform the blob data into an Excel file for easy download, but beware the file is not accessible

My API returns a response containing the content of an excel file, which is displayed in the image below. https://i.sstatic.net/2VHsL.png Now, I am looking to convert this content into an excel file and make it downloadable for the user. Below is the AP ...

Press the button in ng-repeat to send the id to PHP for updating the MySQL entry

I am working on an Angular app that retrieves questions, answers, and explanations from a MySQL database. The main objective is to have a button linked to each question and answer pair that allows for updating or modifying the information in the database. ...