1

你好 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) 

我做错了什么?

4

0 回答 0