javascript - Angular controller can't get 'this' -


i have issue controller when trying 'this' controller gives me other object

in html have created this

<div ng-controller='appcontroller ctrl'>    <input type="text" ng-model='ctrl.firstname'> </div> 

in javascript

app.controller('appcontroller', ['$scope', '$http', ($scope, $http) => {    const ctrl = this; } 

and when trying ctrl.firstname gives me undefined

how can fix issue ? what's wrong here ?

the error getting app not defined in controller file. need declare above, e.g.:

var app = angular.module("myapp", []); 

don't forget pass in necessary dependencies declaration.


Comments