2016-11-18 80 views
1

我对我的指令有些问题。指令未加载

指令和控制器的js文件包含在index.html中,路径是正确的。 在控制台中没有给出错误,但我的标记不呈现。任何帮助都会有所帮助。 下面是一些我的代码

loginForm.js

(function() { 
angular 
    .module('sysConApp') 
    .directive('loginForm', [ 
     function() { 
      return { 
       restrict: 'E', 
       scope: {}, 
       templateUrl: 'scripts/directives/loginForm/view/loginFormView.html', 
       controller: 'LoginFormController', 
       replace: 'true' 
      } 
     } 
    ]); 
}); 

loginFormController.js

angular.module('sysConApp') 
.controller('LoginFormController', ['$scope', '$state', 'AuthService', 'userProfile', 
    function ($scope, $state, AuthService, userProfile) {/*Some codes*/}]); 

loginFormView.html

<form class="loginForm"> 
    <img class="login-logo" 
     src="data:image/png;base64,i..." alt="Logo SysCon"> 
    <input id="inputEmail" 
      type="email" 
      class="form-control" 
      placeholder="E-mail" 
      ng-model="username" 
      required 
      autofocus> 
    <input type="password" 
      id="inputPassword" 
      ng-model="password" 
      class="form-control" 
      placeholder="Senha" 
      required> 
    <span ng-show="loginError && loginForm.$invalid" 
      class="label label-danger"> 
     <b>Erro ao realizar login.</b> Favor tente novamente. 
    </span> 
    <button class="btn btn-lg btn-block btn-signin" 
      ng-disabled="loginForm.$invalid" 
      ng-class="{'btn-default':loginForm.$invalid,'btn-success':loginForm.$valid}" 
      ng-click="logIn()" 
      type="submit"> 
     Log in 
    </button> 
</form> 

的login.html

<div class="card card-container"> 
    <login-form></login-form> 
</div> 

回答

3

你的代码存在的问题是你的IIFE没有被调用过,你只是在创建函数,但从来没有调用它。

你有这样的:

(function() { 
//... 
}); 

而且你必须将其更改为:

(function() { 
//... 
})(); 

全码:

(function() { 
    angular 
    .module('sysConApp') 
    .directive('loginForm', [ 
     function() { 
     return { 
      restrict: 'E', 
      scope: {}, 
      templateUrl: 'scripts/directives/loginForm/view/loginFormView.html', 
      controller: 'LoginFormController', 
      replace: true, 
      link: function(){console.log('whoray');} 
     } 
     } 
    ]); 
})(); 
+0

再次,这么简单的东西,为什么awlays像这个。非常感谢 –

+0

通过拥有IIFE,您可以确定您不会污染全局名称空间。您可以在[此答案](http://stackoverflow.com/a/8228308/7153181)中查看更多关于它的信息。 – Ryota