[英]Error when starting a basic AngularJS app and controller
我在使基本的應用程序和控制器正常工作時遇到了麻煩,盡管我之前多次使用此模式都沒有問題。
這是前端模板的相關部分(我將jinja2與Python webapp2后端一起使用):
{% block js %}
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.min.js"></script>
<script src="/static/js/widget-controller.js"></script>
{% endblock %}
{% block widgetbody %}
<body class="partner_widget" ng-app="PartnerWidgetApp">
<div id="header">Recommended Wired Expert</div>
<div class="body">
<div id="expert_content">
<figure class="headshot">
<img src="{{ expert_user_profile_image }}" />
</figure>
<div class="description" ng-controller="PartnerWidgetController">
<div ng-include="'/static/angular-partials/widget/partner_widget_description.html'">
</div>
</div>
</div>
<div id="action_content">
<a href="#" id="cta">Here's the CTA</a>
</div>
</div>
{% endblock %}
這是我的AngularJS文件:
var PartnerWidgetApp = angular.module('PartnerWidgetApp');
PartnerWidgetApp.controller('PartnerWidgetController', ['$scope',
function($scope) {
$scope.description_text = "this is test text that you should see";
}
]);
以下是包含的“ /static/angular-partials/widget/partner_widget_description.html”文件的內容:
{{ description_text }}
這是我在控制台中的錯誤:
Uncaught Error: No module: PartnerWidgetApp angular.min.js:17
Error: Argument 'PartnerWidgetController' is not a function, got undefined
at Error (native)
at eb (http://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.min.js:16:466)
at va (http://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.min.js:17:33)
at http://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.min.js:53:60
at http://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.min.js:44:43
at o (http://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.min.js:7:43)
at l (http://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.min.js:43:408)
at e (http://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.min.js:39:419)
at e (http://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.min.js:39:436)
at e (http://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.min.js:39:436)
據我所知,Angular庫和我的文件已正確加載,並且應用程序和控制器的名稱與其在模板中的分配一致。 誰能幫助診斷這個問題? 謝謝你的幫助。
var PartnerWidgetApp = angular.module('PartnerWidgetApp');
這是初始化模塊的錯誤方法,請嘗試:
var PartnerWidgetApp = angular.module('PartnerWidgetApp', []);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.