Hi I have StudentController
as follows,
function StudentController($scope,StudentService){
$scope.student = StudentService. getStudent();
$scope.editStudent = function(){
return ngDialog.openConfirm({
template: 'edit-student.html',
className: 'ngdialog-theme-default',
scope : $scope // LINE 1
});
}
}
When editStudent
function is invoked, I want to open a dialog to show edit option. And I want to use the $scope.student
of StudentController
itself in the edit-student.html
as model data. for this feature, I can use scope
property of NgDialog as scope:$scope
(see LINE 1).
Now I am trying to change the StudentController
as suggested in the Angular-StyleGuide where I am not going to use the $scope
in controller
at all. In that case, how can I access student
in edit-student.html
?
function StudentController(StudentService){
var vm = this;
vm .student = StudentService.getStudent();
return ngDialog.openConfirm({
template: 'edit-student.html',
className: 'ngdialog-theme-default',
scope : ???
// $scope is not used in this controller.
//Then what should I send instead?
// I tried using scope : vm . But it didn't work.
});
}
Update : updated with more details to avoid confusion.
I think you're confusing it a bit. If you want to use controllerAs Syntax you need an own controller for the dialog. e.g.
function StudentController(StudentService){
var student = StudentService.getOne();
return ngDialog.openConfirm({
template: template,
className: 'ngdialog-theme-default',
controller: DialogController
controllerAs: 'vm',
resolve: {student: function() {return student; } }
});
}
function DialogController(student) {
var vm = this;
vm.student = student;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With