vendredi 23 janvier 2015

decoupling $scope.form from controller

In my angular controller, I have to reset some form fields to pristine at a certain point (when some other field changes). The code looks something like this ...



$scope.fieldCallback = function() {
$scope.data.Field = undefined;
$scope.form.field.$setPristine();
}


this of course causes problem once I run my unit tests, because form.field will only be there if you actually parse the document (which of course in the case of unit tests is not happening). I know it is possible to do something along the lines of



var element = angular.element(...[some html]...);
$compile(element)($scope);


but this does not really seem like a good solution to me.


Is there any way to decouple the controller from the html so I don't have to mock this like described above?


Thx in advance!


Aucun commentaire:

Enregistrer un commentaire