Angular typeahead引发了我未捕获的错误:没有模块:angularTypeahead。我在我的项目中使用角度预测。 我已将脚本添加到index.html,如下所示:
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.js"></script>
<script src="http://angular-ui.github.com/bootstrap/ui-bootstrap-tpls-0.6.0.js"></script>
<script src="js/angular/app.js"></script>
的index.html:
<div class="row center" ng-app="angularTypeahead">
<div style="margin-top:0px;" class="col l12 s12 m12" ng-controller="TypeaheadCtrl">
<h4 class="header col s12 light">NAME
<input name="location" id="location" type="text"
placeholder="Change Location" ng-model="selected"
typeahead="area for area in areas| filter:$viewValue | limitTo:8"
class="form-control">
</h4>
<a class="waves-effect waves-light btn red">
<i class="material-icons left"></i>Change Location</a>
</div>
</div>
app.js:
(function(){
var app = angular.module('angularTypeahead',['ui.bootstrap']);
app.controller('TypeaheadCtrl', function($scope) {
var areas = ["Alabama", "Alaska", "Arizona", "Arkansas",
"California", "Colorado", "Connecticut", "Delaware",
"Florida", "Georgia", "Hawaii", "Idaho", "Illinois",
"Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana",
"Maine", "Maryland", "Massachusetts", "Michigan",
"Minnesota", "Mississippi", "Missouri", "Montana",
"Nebraska", "Nevada", "New Hampshire", "New Jersey",
"New Mexico", "New York", "North Dakota", "North Carolina",
"Ohio", "Oklahoma", "Oregon", "Pennsylvania",
"Rhode Island", "South Carolina", "South Dakota",
"Tennessee", "Texas", "Utah", "Vermont", "Virginia",
"Washington", "West Virginia", "Wisconsin", "Wyoming"];
$scope.selected = undefined;
$scope.areas = areas;
});
});
我找到了很多关于这个问题的讨论,但没有改变错误。我希望有人能帮助解决这个问题。 谢谢!..
答案 0 :(得分:2)
您应该使用括号调用该函数。 (function(){ ... })()
或者只是不要包装功能。
var app = angular.module();
app.controller();
答案 1 :(得分:0)
在app.js中,您的函数应该是自行执行的,或者称为立即调用函数表达式(IIFE)。为了实现这一目标,您需要更改最后一行:
})();
有关IIFE的更多信息:
https://en.wikipedia.org/wiki/Immediately-invoked_function_expression