dependency injection - why the ui not refresh when data updated in typescript and angularjs program -


I learn typing and analogues for a few days, and now I have a question that confuses me for days, I have a Gps tacking system, so I try to write a service like this: 1.

  Module service {Export class MyService {getGpsPeople (): Array & Lt; AppCommon.GPSPerson & gt; {Var gpsPeople = new arrays & lt; AppCommon.GPSPerson & gt; (Var i = 0; i & lt; 10; i ++) {var tempPerson = New AppCommon.GPSPerson ({name: "user name" + i.toString ()}); GpsPeople.push (tempPerson); } Return GPSSpolle; }} MyService class}  

2. Controller like this:

  Module AppCommon {Export Class Controller {Area: NGIScope; Manufacturer ($ Range: NG. ISSCOP) {this.scope = $ scope; }}} Module controllers {Export interface increases IMyScope ng.IScope {gpsPeople: Array & lt; AppCommon.GPSPerson & gt ;; } Export class MyController extends AppCommon.Controller {Scope: IMI Scope; Static $ injection = ['$ scope', 'myService']; Manufacturer ($ amount: IMI scope, service: services. Myseva) {super ($ scope); $ Scope.gpsPeople = service.getGpsPeople (); }}}  

3. This GPSPerson class looks like this:

  Export class GPSPoint {latitude = 0; Scandal = 0; Manufacturer (LA: number, LG: number) {this.latitude = la; This.longtitude = LG; }} Export interface iPerson {name: string; } Export class GPSPerson {name: string; Previous Location: GPCP; CountFlag = 1; History Location: Array & Lieutenant; GPPNETAT; Timer token: Number; StartTracking () {this.timerToken = setInterval (() => {var newGpsPoint = null; var offside = Math.random (); if (this.countFlag% 2 == 0) {newGpsPoint = new GPSPoint (this. LastLocation .latitude - offside, this.lolocation.langituit - offside);} and {newGpsPoint = new gppoint (this.lolocation.latititude + offside, this.lolocation.langtituit + offside);} this.location = ngps point; this. Pushing historyLocations (newGpsPoint); console.log (this.countFlag.toString () + "+++++++++++++++++++" + this.lastLocation.latitude.toString () + "----" + this.lastLocation.longtitude.toString ()); this.countFlag ++;}, 10000); } StopTracking () {Clarify time (this.timerToken); } Manufacturer (Data: iParan) {this.name = data.name; This.lastLocation = new gppn (123.2, 118.49); This.historyLocations = New Array & gt; GPPNT & gt; (); }}  

The problem is: 1. Can I make GPSPerson class as a controller? 2. The settings work but the UI dosage does not change (when I press the hit button, it changes, the button does nothing)?

I am starting TS and angular, and there is no exercise with JS, I do not know if I explain it clearly, then someone can expect that someone to help me Could!

SetInterval works but UI dos does not change

This is because the code does not run after the completion of $ digest loop setInterval . You should use the $ interval service service as the interval because this is called the reconstruction of the Konari is dirty.

You just MyService Needs access to $ gaps Inject it using $ Inject (see).

1. Can I make a GPSPerson class as a controller?

Not an array controller has a JavaScript object inside and it's okay.


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 -