Hi everyone
 
I have two modals, each using it's own controller and template. I need to 
combine the two into one modal.  Could you help me figure out how to do 
this?  

I haven't used it in a while and trying to re-learn it, I was thinking if 
using ng-controller, rewriting the class files as just a function and 
inserting them into an html page. Then when the user clicks the input, the 
modal with both controllers will display. The way the application is 
structured, I don't know if this can be done or *exactly* how to begin. I 
have the full code in this Plunkr 
<https://plnkr.co/edit/Rtvf7rgGEvJ5a4ScUszK?p=info> (*since it several 
small files*), but I can post some code here as to what I have to start 
with.  I hope this isn't too confusing...

FirstController
export class firstController {
  constructor ($http, $mdDialog, param3, param4) {
    this.isSaving = false;
    this._$mdDialog = $mdDialog;
    this.param3 = param3;
    this.param4 = param4;
    this.categories = 
this.param4.generateCategoriesWithCostForCourse(param3.id, param3.name);
  }

  handleFirstControllerCostChange(category) {
    if (category.cost_change) {
      category.adjusted_cost = (category.base_cost || 0) + 
(category.cost_change || 0);
    } else {
      category.adjusted_cost = category.base_cost;
      category.cost_change_reason = null;
    }
    return category;
  }

  save() {
    //...
  }
}

SecondController
export class firstController {
  constructor ($http, $mdDialog, param3, param4) {
    this.isSaving = false;
    this._$mdDialog = $mdDialog;
    this.param3 = param3;
    this.param4 = param4;
    this.categories = 
this.param4.generateCategoriesWithCostForCourse(param3.id, param3.name);
  }

  handleFirstControllerCostChange(category) {
    if (category.cost_change) {
      category.adjusted_cost = (category.base_cost || 0) + 
(category.cost_change || 0);
    } else {
      category.adjusted_cost = category.base_cost;
      category.cost_change_reason = null;
    }
    return category;
  }

  save() {
    //...
  }
}


Attempt to combine:
export class combinedControllersModalController {
  constructor($http, $mdDialog, param3, param4, param5, param6) {
      this.isSaving = false;
      this._$mdDialog = $mdDialog;
      this.param3 = param3;
      this.param4 = param4;
    //   this.param5 = param5; 
    //   this.param6 = param6;
      this.categories = 
this.param4.generateCategoriesWithCostForCourse(param3.id, param3.name);
    // this.courseData = 
this.param3.getCourseDataForNewStudents(this.param4.course_id, 
this.param5.semester_id);
    // this.courseBaseCost = this.param4.course_category.toUpperCase() == 
'FREE' ? 0 : this.courses.base_cost;
    
      this.handleSecondControllerChange();
  }
  
  handleFirstControllerCostChange(category) {
    if (category.cost_change) {
      category.adjusted_cost = (category.base_cost || 0) + 
(category.cost_change || 0);
    } else {
      category.adjusted_cost = category.base_cost;
      category.cost_change_reason = null;
    }
    return category;
  }


  handleSecondControllerCostChange() {
    if (this.courseData.cost_change) {
      this.courseData.adjusted_cost = (this.courseBaseCost || 0) + 
(this.courseData.cost_adjustment || 0);
    } else {
      this.courseData.adjusted_cost = this.courseBaseCost;
      this.courseData.cost_change_reason = null;
    }
    
  save() {
    //...
    }

  cancel() {
    this._$mdDialog.hide();
  }
  
}

I appreciate your help with this.  It's been a struggle





*PS.  I'm not sure if I duplicated this post because i can't find it and 
this is my first post.  Please excuse me if I duplicated.*

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/angular/4d61b776-e387-4b56-b3c2-f5b4487aa532%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to