Javascript 使用模态从父作用域调用函数(角度)
我有一个main.controller.js,在这个控制器中,我有一个模式,我想在继续应用程序的其余部分之前,用它来通知用户一个警告 例如,我想从模式调用fileNew函数 main.controller.js:Javascript 使用模态从父作用域调用函数(角度),javascript,angularjs,angularjs-scope,modal-dialog,Javascript,Angularjs,Angularjs Scope,Modal Dialog,我有一个main.controller.js,在这个控制器中,我有一个模式,我想在继续应用程序的其余部分之前,用它来通知用户一个警告 例如,我想从模式调用fileNew函数 main.controller.js: $scope.warningModal = function() { $modal.open({ animation: true, templateUrl: "./modal
$scope.warningModal = function() {
$modal.open({
animation: true,
templateUrl: "./modal.html",
controller: "modalController",
});
};
$scope.fileNew = function(type, subject, application) {
newApplication(type, subject, application)
$state.go('submissions');
});
};
$scope.fileNew = function(type, subject, application) {
newApplication(type, subject, application)
$state.go('submissions');
});
};
$scope.fileOld = function(type, subject, application) {
newApplication(type, subject, application)
$state.go('submissions');
});
};
$scope.fileEdit = function(type, subject, application) {
newApplication(type, subject, application)
$state.go('submissions');
});
};
main.html:
<li><a ng-click="warningModal()">New app</a></li>
在控制台中给我一条警告消息说..$scope.$parent.fileNew不是函数
有什么想法吗
编辑:
还有一个关于这个想法的快速问题
我有3种不同类型的文件我要归档的新应用程序
因此,在我的main controller.js中:
$scope.warningModal = function() {
$modal.open({
animation: true,
templateUrl: "./modal.html",
controller: "modalController",
});
};
$scope.fileNew = function(type, subject, application) {
newApplication(type, subject, application)
$state.go('submissions');
});
};
$scope.fileNew = function(type, subject, application) {
newApplication(type, subject, application)
$state.go('submissions');
});
};
$scope.fileOld = function(type, subject, application) {
newApplication(type, subject, application)
$state.go('submissions');
});
};
$scope.fileEdit = function(type, subject, application) {
newApplication(type, subject, application)
$state.go('submissions');
});
};
有没有什么方法可以让我通过在模态控制器上单击相同的继续按钮传递哪个im?在Angular UI引导的最新版本中,您可以包括一个
范围选项,在该选项中,您可以传递希望在模态控制器中可用的范围:
$scope.$parent.fileNew();
$scope.warningModal = function() {
$modal.open({
animation: true,
scope: $scope,
templateUrl: "./modal.html",
controller: "modalController",
});
};
现在您可以从modalController
中调用函数:
$scope.fileNew(type, subject, application);
在Angular UI Bootstrap的最新版本中,您可以包括一个范围
选项,在该选项中,您可以传递希望在模态控制器中可用的范围:
$scope.$parent.fileNew();
$scope.warningModal = function() {
$modal.open({
animation: true,
scope: $scope,
templateUrl: "./modal.html",
controller: "modalController",
});
};
现在您可以从modalController
中调用函数:
$scope.fileNew(type, subject, application);
所以我可以在模态控制器中调用$scope.fileNew?是的!不过,请检查您的版本号。这个功能是最近才出现的。所以我可以在模态控制器中调用$scope.fileNew吗?是的!不过,请检查您的版本号。这个功能是最近才出现的。