嗨我有StudentController如下,
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 }); } }
当调用editStudent函数时,我想打开一个对话框来显示编辑选项.我想在edit-student.html中使用$scope.student的StudentController本身作为模型数据.对于这个特性,我可以使用NgDialog的scope属性作为范围:$scope(参见LINE 1).
现在我正在尝试按照Angular-StyleGuide中的建议更改StudentController,我根本不会在控制器中使用$scope.在这种情况下,我如何在edit-student.html中访问学生?
function StudentController(StudentService){ var vm = this; vm .student = StudentService.getStudent(); return ngDialog.openConfirm({ template: 'edit-student.html',scope : ??? // $scope is not used in this controller. //Then what should I send instead? // I tried using scope : vm . But it didn't work. }); }
更新:更新了更多细节以避免混淆.
解决方法
我觉得你有点困惑.如果要使用controllerAs语法,则需要一个自己的控制器来进行对话.
例如
例如
function StudentController(StudentService){ var student = StudentService.getOne(); return ngDialog.openConfirm({ template: template,controller: DialogController controllerAs: 'vm',resolve: {student: function() {return student; } } }); } function DialogController(student) { var vm = this; vm.student = student; }