gpt4 book ai didi

javascript - AngularJS 应用程序未调用

转载 作者:行者123 更新时间:2023-12-03 06:05:10 25 4
gpt4 key购买 nike

您好,我尝试了很多方法来初始化基本应用程序,但我不知道它出了什么问题。逻辑如下

我使用 jquery ajax 调用“附加”以下包含 Angular js 模块的 html。

('submit', function () {
$.ajax({
type: form.attr('method'),
url: form.attr('action'),
data: form.serialize(),
success: function (data) {
result.html(data);

然后以下 html 与 angularjs 以及具有模块和 Controller 定义的脚本一起加载

HTML:

加载 angular.js 和定义 Angular 应用程序的脚本我在 Body、HTML 或任何地方输入 data-ng-app="app"然后 data-ng-controller="controller"在 div 中或我想要使用范围的任何地方。这应该足以初始化 Controller 。我说得对吗?

脚本:

var app = angular.module('app', []);
app.controller('controller', ["$scope", "$http", function ($scope,$http) {

console.log('works');

...more stuffs
]);

我尝试从教程中最基本的示例中复制粘贴,但仍然不起作用。没有依赖关系或语法错误的问题。可能是什么问题?

提前致谢

最佳答案

我在您的代码中看到的问题是您没有将依赖项传递给您的函数

app.controller("listController", ["$scope", "$http"
function($scope,$http) {
console.log('works');
}]);

DEMO APP

关于javascript - AngularJS 应用程序未调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39581211/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com