lundi 26 juin 2017

error 'moment' is not defined no-undef in ember.js

I'm creating an application, a clock with timezone, it happens that it gives this error and I can not fix it, I'm also an initiator and I do not have much experience, the home page appears where the chosen clock is, but the page where the time zone would be It's blank, I'm waiting for help, thank you!

  • ember-cli: 2.13.1
  • node: 6.0.0
  • os: linux x64

`Could not start watchman Visit http://ift.tt/2huy34z for more info.
Livereload server on http://localhost:49153 'instrument' is imported from external module 'ember-data/-debug' but never used

app/controllers/clock.js
14:36  error  'moment' is not defined  no-undef
18:27  error  'moment' is not defined  no-undef
25:15  error  'moment' is not defined  no-undef

✖ 3 problems (3 errors, 0 warnings)


app/controllers/timezones.js
7:23  error  'moment' is not defined  no-undef
9:19  error  'moment' is not defined  no-undef
10:21  error  'moment' is not defined  no-undef

✖ 3 problems (3 errors, 0 warnings)


Build successful (4919ms) – Serving on http://localhost:4200/



Slowest Nodes (totalTime => 5% )              | Total (avg)         
----------------------------------------------+---------------------
Babel (17)                                    | 1460ms (85 ms)      
Rollup (1)                                    | 1214ms              
EslintValidationFilter (2)                    | 835ms (417 ms)      
Concat (8)                                    | 585ms (73 ms)       
TreeMerger (allTrees) (1)                     | 312ms`               

app/controllers/timezones.js

import Ember from 'ember';

export default Ember.Controller.extend({
/* create array of timezones with name & offset */
init: function() {
    var timezones = [];
    for (var i in moment.tz._zones) {
      timezones.push({
        name: moment.tz._zones[i].name,
        offset: moment.tz._zones[i].offsets[0]
      });
    }
    this.set('timezones', timezones);
    this._super();
  },
  selectedTimezone: null,
  actions: {
    /* save a timezone record to our offline datastore */
    add: function() {
      var timezone = this.store.createRecord('timezone', {
        name: this.get('selectedTimezone').name,
        offset: this.get('selectedTimezone').offset
      });
      timezone.save();
    },        
    /* delete a timezone record from our offline datastore */
    remove: function(timezone) {
      timezone.destroyRecord();
    }
  }
});

app/controllers/clock.js

import Ember from 'ember';

export default Ember.Controller.extend({
init: function() {
    // Update the time.
    this.updateTime();
},

updateTime: function() {
    var _this = this;

    // Update the time every second.
    Ember.run.later(function() {
        _this.set('localTime', moment().format('h:mm:ss a'));

        _this.get('model').forEach(function(model) {
            model.set('time',
                      moment().tz(model.get('name')).format('h:mm:ss 
a'));
        });

        _this.updateTime();
    }, 1000);
},

localTime: moment().format('h:mm:ss a')
});

app/model/timezone.js

import DS from 'ember-data';

export default DS.Model.extend({
name: DS.attr('string'),
offset: DS.attr('number')
});

app/routes/clock.js

import Ember from 'ember';
export default Ember.Route.extend({
model: function() {
    return this.get('store').findAll('timezone');
}
});

app/routes/timezones.js

import Ember from 'ember';
export default Ember.Route.extend({
model: function() {
    return this.get('store').findAll('timezone');
}
});

If you need any more files just talk




Aucun commentaire:

Enregistrer un commentaire