- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 ui-bootstrap 模态窗口,并且我正在尝试测试一种触发该模态窗口的方法。我的 Controller :
app.controller('AddProductController', ['$scope', 'ProductsService', '$uibModal', function ($scope, ProductsService, $uibModal) {
$scope.product = {};
$scope.searchCategories = function () {
ProductsService.getRootCategories().then(function (data) {
$scope.categories = data.data;
});
$scope.modalInstance = $uibModal.open({
animation: $scope.animationsEnabled,
templateUrl: 'categoryContent.html',
controller: 'AddProductController',
scope: $scope
});
$scope.modalInstance.result.then(function (category) {
$scope.searchCategory = null;
$scope.product.category = category;
}, function () {
});
};
$scope.ok = function(){
$scope.modalInstance.close($scope.product.category);
};
$scope.cancel = function(){
$scope.modalInstance.dismiss();
}]);
我的测试:
describe("Products Controller", function () {
beforeEach(function () {
module('productsController');
});
beforeEach(function () {
var ProductsService, createController, scope, rootScope,
module(function ($provide) {
$provide.value('ProductsService', {
getRootCategories: function () {
return {
then: function (callback) {
return callback({data: {name: 'category1'}});
}
};
},
});
$provide.value('$uibModal', {
open : function(){
return {
then: function (callback) {
return callback({data: {name: 'category1'}});
}
};
}
});
return null;
});
});
describe('AddProductController', function () {
beforeEach(function () {
inject(function ($controller, _$rootScope_, _ProductsService_) {
rootScope = _$rootScope_;
scope = _$rootScope_.$new();
ProductsService = _ProductsService_;
createController = function () {
return $controller("AddProductController", {
$scope: scope,
});
};
});
});
it('calling searchCategories should make $scope.categories to be defined', function () {
createController();
expect(scope.categories).not.toBeDefined();
scope.searchCategories();
expect(scope.categories).toBeDefined();
});
});
});
我的所有测试都通过了,除了这个,我得到 TypeError: $scope.modalInstance.result is undefined。有什么线索吗?
最佳答案
您似乎没有在模拟模式中定义结果
。尝试这样的事情:
$provide.value('$uibModal', {
open: function () {
return {
result : {
then: function (callback) {
return callback({ data: { name: 'category1' } });
}
}
};
}
});
关于javascript - 在同一 Controller 内测试 Angular modalInstance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37895722/
我正在尝试像这样使用 angularui-bootstrap 调用模态。 var authApp = angular.module('AuthApp', ['ui.bootstrap']); auth
我有一个带有模态的 Angular 项目,我想在关闭时发送多个(两个)参数,问题是它给出的第二个参数未定义,我的代码如下 /*Modal controller*/ angular.module('as
我正在使用 angular-ui 打开和关闭模式。当我使用 submit(object) 或 dismiss(message) 关闭它时,对话框会关闭,但屏幕仍呈灰色,并且我无法访问我的应用程序。一些
我花了一些时间玩 AngularJS Bootstrap 弹出窗口,并且对于意图它工作得很好,但我想做的是绑定(bind)它,它是同一个 Controller 的依赖脚本,我无法工作不过现在是关闭按钮
我有一个带有模式的应用程序,我试图使用 $modalInstance 调用它。根据我在这里读到的其他问题,我不应该在模板中包含 ng-controller ,这正是我所做的,但它仍然不起作用。 这是我
ModalInstance 数据在导入 Controller 时变为 NULL。我也更改了 modelInstance 名称。但没有成功。这里添加我的代码, SaveController.js sco
我使用 controllerAs 语法来避免在我的 Controller 中出现 $scope soup,并且还使用 ui.bootstrap 来呈现模态视图。 我需要打开一个与当前 Controll
我正在使用 Angular Bootstrap ui modal,它工作正常,但是当我尝试使用 modalInstance 关闭它时,它给出了上述错误。这是我的代码 var app = angul
使用 Angular - UI Bootstrap 我将数据传递到如下所示的 modalInstance 中。在模式中,用户能够创建新项目。按下保存按钮后,新项目将发送到服务器。我需要能够使用 $sc
我正在使用 ui-bootstrap 模态窗口,并且我正在尝试测试一种触发该模态窗口的方法。我的 Controller : app.controller('AddProductController',
我试图展示一个简单的是/否模式,但我从一个问题转到另一个问题。我收到的当前错误消息是: Error: [$injector:unpr] http://errors.angularjs.org/1.6.
在我发现用户未登录后的应用程序中,我想打开一个模式对话框: .when('/showtask/:id', {templateUrl: 'Home/Template/showtask', resol
编写一个测试来测试我的应用程序的删除功能。我创建了一个模拟删除 $modal 来模拟取消/确认删除。 var modalInstanceMock= { result:
当我单击模态上的取消按钮时,与模态模板上的 ng-click 绑定(bind)的 $modalInstance.dismiss 函数不起作用。 控制台抛出错误:“$modalInstance.dism
我正在根据 Google 标准编写代码...甚至不确定这个语法的名称,但它与 Controller 的 Angular-UI 示例代码不同,并且我收到 $modalInstance 的注入(injec
我正在使用 $modalInstance。我希望模式显示在特定的 div 上。我知道我可以使用 window-class,但除此之外,我不确定如何将模式的位置设置在某个 div 之上。 有什么想法吗?
我正在使用 $modalInstance。我希望模式显示在特定的 div 上。我知道我可以使用 window-class,但除此之外,我不确定如何将模式的位置设置在某个 div 之上。 有什么想法吗?
编辑:这篇文章末尾的快速和肮脏的解决方案 我正在使用来自 AngularUI-Bootstrap 的模式窗口,其方式与网站上解释的方式相同,只是我拆分了文件。 因此我有: 调用 Controller
我正在使用 Angular UI Bootstrap ,并希望在非对话框的 View 中重用模式对话框中使用的 Controller 。 我尝试稍后通过手动获取 $modalInstance $inj
我有一个简单的模式,其中包含一个表单。 “确定”按钮应该处理成功并关闭模态,而取消按钮应该只是关闭模态。如果我将“确定”按钮放在表单标签内,模态实例在处理程序中显示为未定义。我需要将按钮放在表单内有两
我是一名优秀的程序员,十分优秀!