你好AngularJS的成员,我是Angular面对这个问题的新手,我的ng-repeat在模型更改后没有刷新页面,即使我已经在帖子后手动重新加载模型了。我创建的所有函数都可以完美地工作,因为我可以在数据库端存储数据/删除,只是它不会在页面刷新时执行,除非我手动点击F5。这是我在js方面的方法。
'use strict';
var eXcomments = angular.module('eXcomments', ['ngAnimate']);
eXcomments.controller('eXcommentsCtrl', function($scope, $http){
$scope.comments;
$scope.inputcomment;
$scope.getComments = function(topic_id){
$http.get('index.php?r=exploreComment/WS_getExploreComments&topic_id=' + topic_id, {cache:false}).success(function(data){
$scope.comments = data;
console.log($scope.comments);
console.log('Comment Loaded');
});
};
$scope.init = function(topic_id){
$scope.getComments(topic_id);
};
$scope.post = function(topic_id){
$scope.getComments(topic_id);
console.log('Reload Comment Success');
};
$scope.makePost = function(topic_id, user_id){
var formatJSON = {
user_id: user_id,
topic_id: topic_id,
data: escape($scope.inputcomment),
};
var json = JSON.stringify(formatJSON);
$http.post('index.php?r=exploreComment/WS_PostComment&json=' + json);
console.log(json);
console.log('posted');
$scope.inputcomment = "";
$scope.getComments(topic_id);
console.log('Reload Comment Success');
};
$scope.removePost = function(topic_id, comment_id){
$http.post('index.php?r=exploreComment/WS_deleteComment&cid=' + comment_id);
$scope.getComments(topic_id);
console.log('Delete');
console.log('Reload Comment Success');
$scope.$apply('comments="null"');
};
});
我为不同的页面处理创建了单独的模块,然后将其注入到这样的根应用程序中。
var myapps = angular.module('myapps',['customDirectives','imgGall','starApp', 'NavBarModel', 'Carousel', 'eXcomments','confirmButton','Status']);
这就是我的HTML布局的样子。
<html>
<!-- Layouts for Comment Display -->
</html>
<div ng-controller="eXcommentsCtrl"
ng-init="init(<?php echo $topic_id?>)" ng-model="comments">
<div class="exploreNoCommentBlock" ng-if="comments.length == 0">
<h4 style="text-align: center">No Comments Yet... How about leaving
yours above?</h4>
</div>
<div class="exploreCommentBlock" ng-repeat="comment in comments">
<table style="width: 100%">
<tr style="width: 100%">
<td style="width: 5%" rowspan="2" valign="top"><img
src="<?php echo UrlMgmt::getUserResourceUrl()?>{{comment.user_id}}/avatar/{{comment.avatar}}"
, style='height: 64px; width: 64px; border-radius: 5px;' /></td>
<td style="width: 70%"><span class="author_name">{{comment.username}}</span>
AND----SO----ON
执行删除操作时会不时地向我显示此错误,从而冻结整个操作,但数据库端会发生更改。
TypeError: undefined is not a function
at Object.h [as fn] (http://localhost/viralenz/themes/viralenz/js/angular-1.2.22/angular.min.js:140:152)
at k.$digest (http://localhost/viralenz/themes/viralenz/js/angular-1.2.22/angular.min.js:109:352)
at k.$apply (http://localhost/viralenz/themes/viralenz/js/angular-1.2.22/angular.min.js:112:345)
at HTMLDivElement.j (http://localhost/viralenz/themes/viralenz/js/ui-bootstrap-0.11.0.min.js:8:1779)
at HTMLDivElement.jQuery.event.dispatch (http://localhost/viralenz/assets/4483d5da/jquery.js:3058:9)
at HTMLDivElement.elemData.handle.eventHandle (http://localhost/viralenz/assets/4483d5da/jquery.js:2676:46)
Error: [$rootScope:inprog] http://errors.angularjs.org/1.2.22/$rootScope/inprog?p0=%24apply
at Error (native)
at http://localhost/viralenz/themes/viralenz/js/angular-1.2.22/angular.min.js:6:450
at m (http://localhost/viralenz/themes/viralenz/js/angular-1.2.22/angular.min.js:105:34)
at k.$apply (http://localhost/viralenz/themes/viralenz/js/angular-1.2.22/angular.min.js:112:276)
at k.$scope.removePost (http://localhost/viralenz/themes/viralenz/js/ng.js:395:10)
at http://localhost/viralenz/themes/viralenz/js/angular-1.2.22/angular.min.js:176:387
at N.(anonymous function) (http://localhost/viralenz/themes/viralenz/js/angular-1.2.22/angular.min.js:53:175)
at k.$eval (http://localhost/viralenz/themes/viralenz/js/angular-1.2.22/angular.min.js:112:15)
at k.$apply (http://localhost/viralenz/themes/viralenz/js/angular-1.2.22/angular.min.js:112:293)
at HTMLButtonElement.<anonymous> (http://localhost/viralenz/themes/viralenz/js/ng.js:103:27)
我做错了什么?