gpt4 book ai didi

html - Angular .js "typeError: V2.example is not a function"错误

转载 作者:太空狗 更新时间:2023-10-29 16:49:00 24 4
gpt4 key购买 nike

我是 angular.js 的新手,我正在学习大约一年前制作的教程我正在尝试创建一个搜索功能,该功能接受输入并在Github.comHTML 代码是:

<!DOCTYPE html>
<html ng-app="github">

<head>
<script src="angular.min.js"></script>
<script src="script.js"></script>
</head>

<body ng-controller="main">
<h1>{{message}}</h1>
<p> {{username}} </p>
<form name="search">
<input type="search" placeholder="enter name" ng-model="username">
<button type="submit" ng-click="search(username)">search</button>
</form>
<div>
<h1> {{user.login}} </h1>
<img src="http://www.gravatar.com/avatar/{{user.gravatar_id}}">
<p> {{user.type}} </p>
</div>
</body>

</html>

和 JS 代码:

// Code goes here
(function () {
var app = angular.module("github", []);
var main = function ($scope, $http) {
var onComplete = function (response) {
$scope.user = response.data;
};
var onError = function (reasone) {
$scope.error = "no can";
};
$scope.search = function (username) {
$http.get("http://api.github.com/users/" +username).then(onComplete, onError);
};
$scope.message = "Git hub viewer";
};
app.controller("main", ["$scope", "$http", main]);
}());

这给了我一个错误>>> TypeError: v2.search is not a function <<<求助:我遇到了这样的问题,解决方案是不在全局类型中使用“main”函数,但我猜“search”不是全局的..希望这有帮助

here is the codepen link:

http://codepen.io/ToBeM12/pen/vGvwzo

最佳答案

该函数与另一个变量同名并且在 $scope 中冲突

在您的情况下,只需将 $scope.search 替换为 $scope.searchuser,因为 $scope.search 已定义..

关于html - Angular .js "typeError: V2.example is not a function"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37058514/

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