1

尝试使用 Angular.js 调用工厂方法时出现一些错误。我在下面解释我的代码。

错误:

TypeError: focusInputField.hoverIn is not a function

我的控制器端代码如下。

var customerNew=angular.module('Spesh');
customerNew.controller('adminCustomerNewController',function($http,$state,$scope,$window,$timeout,Upload,focusInputField){
  $scope.hoverIn=function(id){
      focusInputField.hoverIn(id);
  }
  $scope.hoverOut=function(id){
    focusInputField.hoverOut(id);
  }
})
customerNew.factory('focusInputField',function($timeout, $window) {
    return{
        borderColor:function(id){
             $timeout(function() {
                 var element = $window.document.getElementById(id);
                 if(element){
                      element.focus();
                      element.style.borderColor = "red";
                 }
             });
        },
        clearBorderColor:function(id){
            $timeout(function() {
                var element = $window.document.getElementById(id);
                 if(element){
                     element.style.borderColor = "#cccccc";
                 }
            });
        },
    hoverIn:function(id){
      $timeout(function() {
        var ids='#'+id;
        $(ids).css("cursor","pointer");
        $(ids).animate({width: "100px"}, 'slow');
      });
    },
    hoverOut:function(id){
      $timeout(function() {
        var ids='#'+id;
        $(ids).animate({width: "32px"}, 'slow');
      });
    }
    };
});

在这里,我在调用函数(i.e-hoverIn,hoverOut)时遇到错误。请帮我解决这个错误。

4

0 回答 0