Hit Angularjs $injector: unpr error when creating custom angular directive

时间:2015-05-08 10:04:18

标签: angularjs

I defined blew directive:

<a href="index.php?clearsession=true">Back</a>

For the dependency userService definition:

<?php 

if($_GET['clearsession']){
    session_start();        
    session_unset();
    session_destroy();
    session_write_close();
}

The code works fine on my local machine, but error raised when I deployed the code to the remote ALIYUN machine. I am learning angular and I am not able to figure out what's the problem. How can i fix it?

 define(['angular', './routes', './services', './controllers'], function(angular, userRoutes, userService, userController) {
  'use strict';

  var app = angular.module('yourprefix.user', ['ngCookies', 'ngRoute', 'user.routes', 'user.services']);
  app.directive('pwCheck', function ($document) {
         return {
           restrict: 'A',
           require: 'ngModel',
           link: function (scope, elem, attrs, ctrl) {
             var firstPassword = '#' + attrs.pwCheck;
             elem.add(firstPassword).on('blur', function () {
               scope.$apply(function () {
                 var v = elem.val()===$(firstPassword).val();
                 ctrl.$setValidity('pwmatch', v);
               });
             });
           }
         };
       }).directive('oldPwdCheck', function($document, $log, userService){
         return {
           restrict: 'A',
           require: 'ngModel',
           link: function(scope, elem, attrs, ctrl) {
             var oldPwd = '#' + attrs.oldPwdCheck;
             elem.add(oldPwd).on('blur', function() {
               scope.$apply(function(){
                 var pass = {};
                 pass.value = elem.val();
                 userService.validatePassword(pass).then(function(result) {
                   $log.info(result);
                   ctrl.$setValidity('oldPwdMatch', result);
                 });
               });
             });
           }
         };
       });
  return app;
});

0 个答案:

没有答案