用1.5引用Angular形式

时间:2016-07-21 16:41:01

标签: angularjs angularjs-components angularjs-forms

我有一个角度指令(1.4)我切换到组件语法(1.5)。如果单击表单重置按钮,现有代码将调用表单。$ 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

1 个答案:

答案 0 :(得分:0)

初始化后,在组件控制器上设置间谍。 $ scope不需要传入。

<?php
    // to return plain text
    header("Content-Type: plain/text"); 
    $imei = $_GET["imei"];

    $file=fopen("imei.txt","r") or exit("Unable to open file!");

    while(!feof($file))
     {
    if ($imei==chop(fgets($file)))
     echo "True";
     }

    fclose($file);

?>

在模板中,使用$ ctrl作为表单名称。

ctrl = _$componentController_(
'sbEmployeeCreate', { 
     EmployeeSvc: EmployeeSvc,
     LoggingSvc: LoggingSvc,
     SessionSvc: SessionSvc
});
ctrl.$onInit();
ctrl.myForm = jasmine.createSpyObj('myForm', ['$setPristine']);
相关问题