Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple ng-click not working in typescript

I'm trying to call a function in click function from my html page , added all typescript definition files from nuget but something is going wrong My Click Function is not Working .... No error in console even

Here is my Hrml and Controller Code

Html Page

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">


<head>
    <script src="Scripts/angular.js"></script>

    <script src="test.js"></script>
    <title></title>

</head>
<body ng-app="testModule">
    <div ng-controller="test">
        <input type="button" ng-click="click()" value="test" />
    </div>
</body>
</html>

Controller

angular.module("testModule", []);

class test {

    constructor() { }

    click() {

        alert();
    }
} 


angular.module("testModule").controller("test", test );
like image 725
sudhir Avatar asked Dec 05 '22 01:12

sudhir


1 Answers

This does not work because ng-click="click()" tries to call $scope.click() which is not defined.

I would highly advise you to use the controller as-Syntax when working with AngularJS and Typescript

Demo

like image 188
Aides Avatar answered Dec 09 '22 15:12

Aides