【发布时间】:2016-11-25 09:04:28
【问题描述】:
我有一个角度指令 (1.4) 我正在切换到组件语法 (1.5)。如果单击表单重置按钮,现有代码将调用 form.$setPristine()。当我将它切换到一个组件并尝试从 jasmine 测试中调用时,表单变量是未定义的。
ctrl.resetForm = function () {
ctrl.employee = {};
ctrl.myForm.$setPristine();
};
测试文件:
$scope = $rootScope.$new();
$scope.myForm = jasmine.createSpyObj('myForm', ['$setPristine']);
ctrl = _$componentController_(
'myComponent', {
$scope: $scope,
EmployeeSvc: EmployeeSvc,
LoggingSvc: LoggingSvc,
SessionSvc: SessionSvc
});
ctrl.$onInit();
form.html
<form name="myForm" class="form" novalidate>
错误:
debug.html:38 TypeError: Cannot read property '$setPristine' of undefined
【问题讨论】:
-
模板代码是什么?你是否尝试过像
ctrl.myForm = {}这样初始化表单 -
如果您可以在 plunker 中提供一些东西会有所帮助。
标签: angularjs angularjs-components angularjs-forms