Html 无限循环角

Html 无限循环角,html,angularjs,jsp,Html,Angularjs,Jsp,我有一个jsp页面,在其中我使用参数调用一个angularjs函数。该函数发出get http请求,并将结果存储到控制器中的变量。但当我从jsp页面调用该函数时,我得到一种情况,这些http请求被无限次地反复发送。如何停止该循环并只对函数进行一次调用 在jsp中,我有: {{ getFriends('john') }} //call to angularjs function to retrieve all of John's friends 在js中: $scope.friends = n

我有一个jsp页面,在其中我使用参数调用一个angularjs函数。该函数发出get http请求,并将结果存储到控制器中的变量。但当我从jsp页面调用该函数时,我得到一种情况,这些http请求被无限次地反复发送。如何停止该循环并只对函数进行一次调用

在jsp中,我有:

 {{ getFriends('john') }} //call to angularjs function to retrieve all of John's friends
在js中:

$scope.friends = null;

        $scope.getFriends = function(username){

            $http.get("services/rest/getFriends?username="+username).then(function(response){
                $scope.friends = response.data;
                console.info(response.data);
            }, function(response){

            });

        }
我发现以下错误:

angular.min.js:sourcemap:123 Error: [$rootScope:infdig] http://errors.angularjs.org/1.6.3/$rootScope/infdig?p0=10&p1=%5B%5D
at angular.min.js:sourcemap:6
at m.$digest (angular.min.js:sourcemap:147)
at m.$apply (angular.min.js:sourcemap:149)
at l (angular.min.js:sourcemap:102)
at XMLHttpRequest.v.onload (angular.min.js:sourcemap:107)
jsp的完整代码:

   <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html ng-app = "profil">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script src="${pageContext.request.contextPath}/js/angular.min.js"></script>
<script src="${pageContext.request.contextPath}/js/profil.js"></script>

<title>Insert title here</title>
</head>
<body ng-controller="appController">

<!-- {{ getFriends('pera') }} -->
{{ getFriends('${userDetails.username }') }}

Ime: ${userDetails.ime } </br>
Prezime: ${userDetails.prezime } </br>
Korisnicko ime: ${userDetails.username } </br>
<img src="${pageContext.request.contextPath}/slike/${userDetails.slika}" alt="${userDetails.username }" height="50px"> </img>

</body>
</html>
其他控制员:

@RequestMapping("user-details/{username}")
public String showUserDetails(@PathVariable String username, Model model) throws SQLException {
    model.addAttribute("userDetails",dbHelper.getKorisnik(username));
    return "/profil.jsp";
}
@RequestMapping(path="getPrijatelji",method = {RequestMethod.GET} , produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
    public List<Korisnik> getPrijatelji(@RequestParam(name = "username") String username) throws SQLException{
        return dbHelper.getPrijatelji(username);
    }
@RequestMapping(path=“getPrijatelji”,method={RequestMethod.GET},products={MediaType.APPLICATION\u JSON\u UTF8\u VALUE})
公共列表getPrijatelji(@RequestParam(name=“username”)字符串username)引发SQLException{
返回dbHelper.getPrijatelji(用户名);
}

您可以在ng init中调用函数,而不是调用占位符或ng bind。

尝试在API的.then中返回一些内容call@Vivz什么都没有,仍然循环。是否在jsp页面上呈现了一些内容?控制台中是否有错误?@Vivz我刚开始使用jsp,所以我对它不太熟悉,渲染是什么意思?@wdc您正在调用
getFriends('${userDetails.username}')
在角度表达式中,您应该在
nginit
或任何其他单击事件中调用它。