在我尝试使用的模态控制器中 this.cancel = function()....但函数永远不会被调用。 我不得不把它改成$ scope.cancel ....让它起作用,我试图理解为什么会这样。
这个。“无论什么”在主控制器中起作用
代码段:
function MainController($uibModal) {
//this works
this.popup = function () {
$uibModal.open({
controller: 'PopupCtrl',
templateUrl: 'myctrl.html'
});
};
}
function PopupController($scope, $uibModalInstance) {
//"this.cancel" does not work, need to use $scope
$scope.cancel = function (){
$uibModalInstance.dismiss();
};
//"this" wont work
this.ok = function (){
$uibModalInstance.dismiss();
};
}
我创建了一个Plunker来展示示例
答案 0 :(得分:1)
-- Helper table for generating ASCII characters
CREATE TABLE incr( id INT IDENTITY );
INSERT INTO incr VALUES (1), (2), (3), (4), (5), (6), (7), -- snip, to 255
-- reusing table despite now-inaccurate name
TRUNCATE TABLE has_hyphens;
INSERT INTO has_hyphens
SELECT 'FOO'+CHAR(AVG(id))+' bar' FROM incr
CROSS APPLY sys.dm_fts_parser('"word1'+CHAR(id)+'word2"', 1033, 0, 0) fts
WHERE id<>34 AND id<256
GROUP BY id
HAVING COUNT(fts.keyword)>1; -- generate all 'FOO'+[breaker character]+' bar'
-- combinations
SELECT * FROM has_hyphens WHERE NOT CONTAINS(t, 'FOO');
这里的关键是语法&#34; PopupCtrl as popupctrl&#34;
popupctrl是对模态控制器的引用。在视图中我这样做了:
this.popup = function () {
$uibModal.open({
controller: 'PopupCtrl as popupctrl',
templateUrl: 'myctrl.html'
});
请注意,我使用了#34;参考&#34;。