无法使用Angular.js调用工厂方法

时间:2017-03-17 06:38:13

标签: javascript angularjs angular-factory

尝试使用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)时遇到错误。请帮我解决这个错误。

0 个答案:

没有答案