Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 自动添加新项-角度UI查询_Angularjs - Fatal编程技术网

Angularjs 自动添加新项-角度UI查询

Angularjs 自动添加新项-角度UI查询,angularjs,Angularjs,我在一个网站上添加了一个“新故事”功能,供作者贡献作品。下面的功能允许创建故事并将其添加到作者的个人资料中,但不会自动将其添加到列表中(即我必须刷新浏览器才能使其正常工作。是否有人知道是否有办法做到这一点(我已尝试将状态改回“authorprofile”,但没有成功) 假设故事列表存储在范围上的“故事”变量中: // auto-add new stories here $scope.stories.push(data); 在success函数中使用push方法将新故事添加到数组中 Stor

我在一个网站上添加了一个“新故事”功能,供作者贡献作品。下面的功能允许创建故事并将其添加到作者的个人资料中,但不会自动将其添加到列表中(即我必须刷新浏览器才能使其正常工作。是否有人知道是否有办法做到这一点(我已尝试将状态改回“authorprofile”,但没有成功)


假设故事列表存储在范围上的“故事”变量中:

// auto-add new stories here
$scope.stories.push(data);

在success函数中使用push方法将新故事添加到数组中

  Story.save(data, function(story) {
      //Add stories to the array
      $scope.stories.push(story);
      Story.put(data, function(story){
        console.log("story added");
      })
      // auto-add new stories here
      $state.go('authorprofile');
})

谢谢fikkatra,我还没有完全理解它,但我会用$scope玩一玩
  Story.save(data, function(story) {
      //Add stories to the array
      $scope.stories.push(story);
      Story.put(data, function(story){
        console.log("story added");
      })
      // auto-add new stories here
      $state.go('authorprofile');
})