Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/405.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Angular 1自定义指令未执行_Javascript_Angularjs_Angular Directive - Fatal编程技术网

Javascript Angular 1自定义指令未执行

Javascript Angular 1自定义指令未执行,javascript,angularjs,angular-directive,Javascript,Angularjs,Angular Directive,我的指令定义如下: 'use strict;' angular.module('clientApp') .directive('afterLast', ['$ocLazyLoad','$timeout',function($ocLazyLoad, $timeout){ console.log('entered directive'); return { restrict: 'A', link: function(scope, elem, att

我的指令定义如下:

'use strict;'

angular.module('clientApp')

.directive('afterLast', ['$ocLazyLoad','$timeout',function($ocLazyLoad, $timeout){
    console.log('entered directive');
    return {
        restrict: 'A',
        link: function(scope, elem, attr){
            if (scope.$last === true){
                console.log('entered directive')
                $timeout(function(){
                    $ocLazyLoad.load(['some files'])   
                })
            }
        }
    }
}]);
<div ng-repeat="topicObject in module.topics track by $index" afterLast>

  <div class="ft-section">

    <div ng-repeat="learningPointObject in topicObject.learningPoints track by $index">
        <div class="ft-page">
            <h2 class="module-name" style="text-align: center;">{{module.name | capitalize:true}}</h2>
            <h3 class="topic-name">{{topicObject.name | capitalize:true}}</h3>
            <h4>{{learningPointObject.name | capitalize}}</h4>
            <hr>
         </div>
     </div>

  </div>

</div>  
我使用它作为属性,如下所示:

'use strict;'

angular.module('clientApp')

.directive('afterLast', ['$ocLazyLoad','$timeout',function($ocLazyLoad, $timeout){
    console.log('entered directive');
    return {
        restrict: 'A',
        link: function(scope, elem, attr){
            if (scope.$last === true){
                console.log('entered directive')
                $timeout(function(){
                    $ocLazyLoad.load(['some files'])   
                })
            }
        }
    }
}]);
<div ng-repeat="topicObject in module.topics track by $index" afterLast>

  <div class="ft-section">

    <div ng-repeat="learningPointObject in topicObject.learningPoints track by $index">
        <div class="ft-page">
            <h2 class="module-name" style="text-align: center;">{{module.name | capitalize:true}}</h2>
            <h3 class="topic-name">{{topicObject.name | capitalize:true}}</h3>
            <h4>{{learningPointObject.name | capitalize}}</h4>
            <hr>
         </div>
     </div>

  </div>

</div>  

{{module.name |大写:true}
{{topicObject.name |大写:true}
{{learningPointObject.name | capitalize}}

但我的指令没有执行。甚至link函数内外的console.log语句也不起作用。 1.我使用指令的方式正确吗?
2.如果是,它不起作用的原因可能是什么?

在HTML中,指令名称必须是kebab大小写,而不是camelCase

 <!-- ERRONEOUS camelCase
 <div ng-repeat="topicObject in module.topics track by $index" afterLast>
 -->

 <!-- USE kebab-case -->
 <div ng-repeat="topicObject in module.topics track by $index" after-last>


有关更多信息,请参见HTML中的

,指令名称必须是kebab大小写,而不是camelCase

 <!-- ERRONEOUS camelCase
 <div ng-repeat="topicObject in module.topics track by $index" afterLast>
 -->

 <!-- USE kebab-case -->
 <div ng-repeat="topicObject in module.topics track by $index" after-last>


有关更多信息,请参阅指令:有关ng repeat的最后一次观察。。 应用指令('afterLast',函数(){ 返回{ 限制:“A”, 作用域:{}, 链接:函数(范围、元素、属性){ if(attrs.ngRepeat){ if(范围$parent.$last){ 如果(attrs.afterLast!=''){ if(作用域的类型。$parent.$parent[attrs.afterLast]=='function'){ //执行定义的函数 作用域:$parent.$parentattrs.afterLast; }否则{ //如果你愿意的话,给《守望者》 scope.$parent.$parent[attrs.afterLast]=true; } } } }否则{ 抛出使用此指令所需的“ngRepeatEndWatch:
ngRepeat
指令”; } } } });

上次调用时的函数调用

$scope.layoutDone=函数(){

你想要你的欲望数据在这里

}

html

{{module.name |大写:true} {{topicObject.name |大写:true} {{learningPointObject.name | capitalize}}

指令:用于ng重复的最后一次观察。。 应用指令('afterLast',函数(){ 返回{ 限制:“A”, 作用域:{}, 链接:函数(范围、元素、属性){ if(attrs.ngRepeat){ if(范围$parent.$last){ 如果(attrs.afterLast!=''){ if(作用域的类型。$parent.$parent[attrs.afterLast]=='function'){ //执行定义的函数 作用域:$parent.$parentattrs.afterLast; }否则{ //如果你愿意的话,给《守望者》 scope.$parent.$parent[attrs.afterLast]=true; } } } }否则{ 抛出使用此指令所需的“ngRepeatEndWatch:
ngRepeat
指令”; } } } });

上次调用时的函数调用

$scope.layoutDone=函数(){

你想要你的欲望数据在这里

}

html

{{module.name |大写:true} {{topicObject.name |大写:true} {{learningPointObject.name | capitalize}}

在HTML元素中,您的指令是由
after last
引用的,而不是
after last
是的,这是我错过的。谢谢:)在HTML元素中,您的指令是由
after last
引用的,而不是
after last
是的,这是我错过的。谢谢:)