javascript - Can I avoid using the word "this" inside Typescript when calling a function that came in through a constructor? -


I have:

  class AdminHomeController {personal configuration 1; // I tried different forms here, but nobody has configured 2 public; // Constructor (Private $ area: IAdminHomeControllerScope) {this.config = $ scope.config; // & lt; & Lt; This works) Fixed $ injection = ['$ scope']; ConfigChanged = (explicit) = & gt; {This.config.clear (); }; }  

This code works and requires all the methods in this.config though there is a way that I this Can I remove the requirement? I want to be able to do the following code:

  configChanged = (clear) => {Config.clear (); };  

I tried with many different forms but I can not get it to do this work.

  angular.module ('admin') .controller ('AdminHomeController', ['$ http',  

Here is an example of a single code before typing here . '$ Q', '$ scope', 'utility service', administrator main controller]); Function adminHomeController ($ http, $ q, $ scope, utilityService) {var app = $ scope.app; Var config = app.config; WORLD HOME = THIS; Var util = utilityService; Home.autoSave = false; Home.data = {}; Home.entityType = null; Home.forms = {grid: null, modal: null}; Home.grid = {Views: [], Data: []}; Home.modal = {Views: False}; Home.row = {}; Home.rowSelected = null; Home.configChanged = function (clear) {config.put (); If (clear) {home.grid.backup = []; Home.grid.data = []; }}; As djechilin said,

If you come to "this," the interpreter will only search the variable name in local, shut down and global scope, actually does not see the object properties

so that you can potentially move that task You can type definition in the constructor's body (from which you have access to the closure $ scope variable). Here, we also turn off config and use it in the function:

Admin Admin AdminHomeController {configChanged: () => Zero; // Function Constructor is required to be declared (Private $ Range: Any) {var config = $ scope.config; This.configChanged = () = & gt; {// and then provide it config.clear (); }; }}

As you can see, it is not elegant. You have definition definition + announcement division. Besides this, the constructor body is being unnecessarily heavy.

Typecript does not blame here. This is just javascript.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -