AngularJs+TypeScript:- How to assign the value of a variable to textfield -


i have taken 2 div 1 left aligned , second right.in both div having textbox.i gave ng-href on trying copy data of left div right div it's not going in way.it doesn't anything. here html code:-

<div data-ng-app="customernew" data-ng-controller="createcustomerctrl custom" data-ng-init="getformdata();data();">     <div id="div1" align="left">     <tr>      <td style="width: 200px">first name:</td>     <td>     <asp:textbox id="txtfirstname" tabindex="1" runat="server" cssclass="normaltextbox"width="160px" height="10px" name="txtfirstname" ng-model="custom.txtfirstname"></asp:textbox>     </td>     </tr>     </div> 

<div id="div2" align="right"> <tr> <td colspan="2" width="100"> <a ng-href="" width="147px" style="cursor:pointer;" tabindex="12"  ng-click="buttoncopy(custom.txtfirstname)">copy contact info</a> </td> </tr>  <tr> <td style="width: 200px">first name:</td> <td> <asp:textbox id="txtfirstnamebilling" tabindex="12" runat="server" cssclass="normaltextbox"width="160px" height="10px" ng-model="custom.txtfirstnamebilling"></asp:textbox> </td> </tr> </div> 

assignment of values:-

    /// <reference path="../interface/interface.ts" />     /// <reference path="../../scripts/typings/jquery/jquery.d.ts" />     /// <reference path="../../scripts/typings/angularjs/angular.d.ts" />      module customernew.controllers {         export class createcustomerctrl {             static $inject = ['$scope', '$http', '$templatecache'];             debugger;             constructor(protected $scope: icustomerscope,                 protected $http: ng.ihttpservice,                 protected $templatecache: ng.itemplatecacheservice) {                 $scope.buttoncopy = this.buttoncopy;             }      public buttoncopy = (firstname) => { this.$scope.txtfirstnamebilling = firstname;             }             //end         }         var customerapp = angular.module("customernew", []);         customerapp.controller('createcustomerctrl', customernew.controllers.createcustomerctrl);     } 

my interface

module customernew {     export interface icustomerscope extends ng.iscope {         buttoncopy: (firstname) => void;     } } 

i have tried in different way suggested dean ward new problem occurs

error image updated error2

![enter image description here][2]

you're using controlleras syntax. in case shouldn't using scope:

public buttoncopy = (firstname) => {     this.txtfirstnamebilling = firstname; } 

and should specifying ng-click custom prefix:

<a ng-href="" width="147px" style="cursor:pointer;" tabindex="12"  

ng-click="custom.buttoncopy(custom.txtfirstname)">copy contact info

example snippet:

var customerapp = angular.module("customernew", []);  customerapp.controller('createcustomerctrl', [    "$scope", "$http", "$templatecache",     function($scope, $http, $templatecache) {      this.buttoncopy = function(firstname) {        console.log("boom");        this.txtfirstnamebilling = firstname;      }    }  ]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>  <div data-ng-app="customernew" data-ng-controller="createcustomerctrl custom">      <div id="div1" align="left">      <tr>       <td style="width: 200px">first name:</td>      <td>      <input ng-model="custom.txtfirstname" />      </td>      </tr>      </div>  <div id="div2" align="right">  <tr>  <td colspan="2" width="100">    <button ng-click="custom.buttoncopy(custom.txtfirstname)">copy contact info</button>  </td>  </tr>   <tr>  <td style="width: 200px">first name:</td>  <td>  <input ng-model="custom.txtfirstnamebilling">  </td>  </tr>  </div>

your subsequent typescript issues related undefined fields on class used controller. in case changing class definition follows fix it:

export class createcustomerctrl {     static $inject = ['$http', '$templatecache'];         constructor(             protected $http: ng.ihttpservice,             protected $templatecache: ng.itemplatecacheservice) {         }          public txtfirstnamebilling: string;         public txtfirstname: string;         public buttoncopy = (firstname) => {             this.txtfirstnamebilling = firstname;         }     } 

Comments