Skip to main content
 首页 » 编程设计

python之AngularJS+Flask 无法实例化模块

2024年10月01日49shangdawei

<分区>

我几乎到处都在寻找这个,但如果我遗漏了什么,请原谅我。 这是我的 html:

<!DOCTYPE html> 
<html> 
<head> 
    <title>PDFHandle</title> 
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.5/angular.js"></script> 
    <script type="text/javascript" src="{{ url_for('static', filename='custom.js') }}"></script> 
</head> 
<body> 
    {% raw %} 
        <div ng-app="uploadApp" ng-controller="UploadController as uc"> 
            <div ng-repeat="choice in uc.choices"> 
                <input value="{{choice.value}}" /> 
            </div> 
            <button ng-click="uc.addChoice()">Add</button> 
        </div> 
    {% endraw %} 
</body> 
</html> 

这是我的 AngularJS 脚本:

var Try = angular.module("uploadApp", []) 
.controller("UploadController", function UploadController() { 
    this.choices = [{id: "choice1", value:"Hello"}]; 
    this.addChoice = function() { 
        return this.choices.push({id:"choice"+(this.choices.length+1), value:"Hello Again"}); 
    }; 
}) 

我面临的问题是这个(在 Chrome 的开发者工具中显示):

Uncaught Error: [$injector:modulerr] Failed to instantiate module uploadApp due to: 
Error: [$injector:nomod] Module 'uploadApp' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument. 

我可以通过正常地将它与 HTML 文件链接来运行它,只是当我尝试将它与 flask 渲染的 HTML 一起使用时它不起作用。我也尝试过使用其他 Angular IDE 进行此操作,并且在它们中也运行良好。就像我说的,只是不适用于 flask 。 任何帮助将不胜感激。谢谢!