将范围传递给指令($uibModal.open 方法)
Pass scope to directive ($uibModal.open method)
我想创建自定义指令以显示基于父级(控制器)范围的一些数据。
指令JS代码:
(function () {
'use strict';
angular
.module('blabla')
.directive('showActiveTask', showActiveTask);
showActiveTask.$inject = ['$uibModal'];
function showActiveTask($uibModal) {
return {
//replace: true,
restrict: 'E',
scope: {
taskData: '='
},
template: '<button type="submit"' +
' class="btn grey lighten-1 btn-raised white-text btn-sm"' +
' ng-click="open()">' +
' <span class="hidden-xs hidden-sm">View assigned tasks</span>' +
'</button>',
link: linkFunc
};
function linkFunc(scope, element, attrs) {
var vm = this;
vm.showLabel = false;
console.log(scope);
scope.open = function () {
vm.modalInstance = $uibModal.open({
templateUrl: 'blabla.html',
size: 'lg',
controller: scope.taskData,
backdrop: true,
resolve: {
console.log('babla')
}
}
}).result.then(function () {
console.log("wanna switch");
});
console.log(scope)
};
scope.clear = function () {
console.log('close modal');
vm.modalInstance.close();
};
}
}
})();
控制器JS代码:
当我单击以显示此指令时,我收到消息:"Argument 'fn' is not a function, got Object" - 很明显,因为我试图将范围对象作为控制器传递,但这里:http://brilliantbritz.com/2014/08/09/create-a-dynamic-modal-directive-in-minutes-using-angular-and-ui-bootstrap/ 是相同的。我做错了什么?
该死的。很明显:要根据父控制器范围创建模态,只需将其范围作为参数传递即可:
scope.open = function () {
vm.modalInstance = $uibModal.open({
templateUrl: 'blabla.html',
size: 'lg',
scope: scope,
backdrop: true,
resolve: {
text: function () {
return '<strong><p>Are you sure you want to close?</p></strong>'
}
}
}).result.then(function () {
console.log("wanna switch");
});
};
我想创建自定义指令以显示基于父级(控制器)范围的一些数据。
指令JS代码:
(function () {
'use strict';
angular
.module('blabla')
.directive('showActiveTask', showActiveTask);
showActiveTask.$inject = ['$uibModal'];
function showActiveTask($uibModal) {
return {
//replace: true,
restrict: 'E',
scope: {
taskData: '='
},
template: '<button type="submit"' +
' class="btn grey lighten-1 btn-raised white-text btn-sm"' +
' ng-click="open()">' +
' <span class="hidden-xs hidden-sm">View assigned tasks</span>' +
'</button>',
link: linkFunc
};
function linkFunc(scope, element, attrs) {
var vm = this;
vm.showLabel = false;
console.log(scope);
scope.open = function () {
vm.modalInstance = $uibModal.open({
templateUrl: 'blabla.html',
size: 'lg',
controller: scope.taskData,
backdrop: true,
resolve: {
console.log('babla')
}
}
}).result.then(function () {
console.log("wanna switch");
});
console.log(scope)
};
scope.clear = function () {
console.log('close modal');
vm.modalInstance.close();
};
}
}
})();
控制器JS代码:
当我单击以显示此指令时,我收到消息:"Argument 'fn' is not a function, got Object" - 很明显,因为我试图将范围对象作为控制器传递,但这里:http://brilliantbritz.com/2014/08/09/create-a-dynamic-modal-directive-in-minutes-using-angular-and-ui-bootstrap/ 是相同的。我做错了什么?
该死的。很明显:要根据父控制器范围创建模态,只需将其范围作为参数传递即可:
scope.open = function () {
vm.modalInstance = $uibModal.open({
templateUrl: 'blabla.html',
size: 'lg',
scope: scope,
backdrop: true,
resolve: {
text: function () {
return '<strong><p>Are you sure you want to close?</p></strong>'
}
}
}).result.then(function () {
console.log("wanna switch");
});
};