user8563589
user8563589

Reputation: 3

how to access model data returned from model hook in the same route (in ember)?

The project's data will be edited in a template. Without saving it if i navigate to other link willTransition action will be executed but how to access the 'project' model data within the same route?? (without using controller)

//routes/records/edit

    return RSVP.hash({
        project: this.get('store').findRecord('project', params.id),
        ..: this.get('store').findAll('...')
    });
},
actions: {
    willTransition(transition) {
        if (project.isDirty) { //how to use project which is returned by model hook
            if (!confirm('unsaved is it okay!!!')) {
                transition.abort();
            }
        }
    }

Upvotes: 0

Views: 303

Answers (2)

BrandonW
BrandonW

Reputation: 268

this.modelFor('record').project.get('hasDirtyAttributes');

.modelFor('record') will get the model from the route record, .project will get the RSVP within that model, and .get('hasDirtyAttributes') is a property of the model data that is set to true if the model data has changed.

Upvotes: 0

Sandeep
Sandeep

Reputation: 605

this.controller.get('model') should return the model if you are setting your 'project' in model or if it is a controller property then can be accessed by this.controller.get('project')

Upvotes: 1

Related Questions