我正在摆弄angular.js并且必须包含一个名为flipclock.js的jquery插件。我google了很多,发现这个article关于在一个角度指令中包装jquery。
我看着它并用flipclock做了同样的事 - 看起来像这样
var app = angular.module('flipClock', []);
app.directive('FlipClock', function(){
return {
restrict: 'A',
link: function(scope, element, attrs){
$(element).FlipClock(scope.$eval(attrs.FlipClock));
}
}
});
使用以下标记
<div ng-App="flipClock">
<div id="countdown" class="countdown" flipclock="{}"></div>
</div>
但没有发生任何事情,我得到错误:
Uncaught ReferenceError: Base is not defined - flipclock.js:37
并且:37只是FlipClock.Base = Base.extend({ ...
我的html中源代码的顺序是:
<script src="components/jquery/jquery.js"></script>
<script src="components/angular/angular.js"></script>
<script src="components/angular-resource/angular-resource.js"></script>
<script src="components/angular-cookies/angular-cookies.js"></script>
<script src="components/angular-sanitize/angular-sanitize.js"></script>
<!-- build:js scripts/scripts.js -->
<script src="scripts/app.js"></script>
<script src="scripts/controllers/main.js"></script>
<script src="scripts/controllers/pre.js"></script>
<!-- endbuild -->
<!-- build:js scripts/main.js -->
<script src="components/flipclock/libs/prefixfree.min.js"></script>
<script src="components/flipclock/flipclock.js"></script>
答案 0 :(得分:3)
指令定义名称区分大小写。它与HTML中的名称不匹配。尝试更改:
app.directive('FlipClock', function(){
到
app.directive('flipclock', function(){
和
$(element).FlipClock(scope.$eval(attrs.FlipClock));
到
$(element).FlipClock(scope.$eval(attrs.flipclock));