Angularjs:从资源查询将数据推送到数组并在ngRepeat中显示

时间:2015-07-11 05:33:14

标签: angularjs

使用restful API$resource检索到的数组数据,我使用query()方法获取它。所以我创建了一个新数据,我想将$resource中创建的数据推送到ngRepeat self.submit = function(){ //This function is called when i submit data creation var form = self.form; form.user_id = Global.user.id; // hide error message if it's shown self.data.error.show = false; // check if submition is already on request (for some reason it submit twice) if(!self.status.request){ self.status.request = true; $timeout(function(){ projects.save({data: form}, function(data){ //function called from $resource console.log(data); self.status.request = false; // Resolve Error if(data.error[1]) resolveError(); // merge data to list else{ form.id = data.id; mergeData(form); self.closeDialog(); } }); }, 1000) } // show error message function resolveError(){ var error = self.data.error; error.show = true; } // merge form data into list data function mergeData(data){ self.query.push(data); //this doesn't seem to work console.log(data, self.query); //log to see if data is in array } } 指令中,但是当我执行推送功能时,它不会推送而且我不想再次重新查询整个数据。

控制器

<md-card ng-repeat="project in projects.query | orderBy:'id':true">
    <md-toolbar>
        <div class="md-toolbar-tools">
            <h2>{{project.Name}}</h2>
            <span flex></span>
            <h3>{{project.user_id}}</h3>
        </div>
    </md-toolbar>
    <md-card-content>
        <p>{{project.Description}}</p>
    </md-card-content>
    <div class="md-actions" layout="row" layout-align="end center">
        <md-button ng-href="#/projects/{{project.id}}">View</md-button>
    </div>
</md-card>

视图

projects

注意: 数据保存在数据库中,目前在列表中查看数据的唯一方法是刷新页面

更新: ProjectsController$http({'method' : 'get', 'url' : '/views/adminpanel/'+url;的别名

0 个答案:

没有答案