我在使用基本应用程序和控制器时遇到了问题,尽管我之前已多次使用此模式而没有问题。
这是我的前端模板的相关部分(我正在使用带有Python webapp2后端的jinja2):
{% 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库和我的文件,应用程序和控制器的名称与模板中的分配一致。任何人都可以帮助诊断这个问题吗?谢谢你的帮助。
答案 0 :(得分:2)
var PartnerWidgetApp = angular.module('PartnerWidgetApp');
这是初始化模块的错误方法,请尝试:
var PartnerWidgetApp = angular.module('PartnerWidgetApp', []);