Issue with AngularJs change detection in a typescript controller

11 views
Skip to first unread message

Julien Martin

unread,
Nov 11, 2020, 2:18:45 AM11/11/20
to Angular and AngularJS discussion
Hello,

I am working on an AngularJs typescript application (**AngularJs 1.7.8**). Somehow, a variable is not updated in the template.

My AngularJs component:

    export class AppComponent {
        // Define our AppComponent's name
        static componentName: string = "msApp";
    
        // Define our AppComponent's config
        static componentConfig: ng.IComponentOptions = {
            bindings: {},
            controllerAs: 'vm',
            controller: AppComponent,
            templateUrl: 'src/components/start-app/start-app.component.html'
        };
    
        aParam: string;
    
        searchCallback(param: string) {
            this.aParam = param;
        }

within the HTML template:

    '{{vm.aParam}}'

When the `searchCallback` is invoked, the template doesn't update `vm.aParam`. I suspect it is a change detection issue because if I initialize `aParam` in the controller as follows:

    aParam: string = 'foo';

then the template does display 'foo'.

Can someone please help?
Reply all
Reply to author
Forward
0 new messages