Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/475.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.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
Javascript AngularJS模态不';t将创建的值返回到数组_Javascript_Angularjs_Twitter Bootstrap - Fatal编程技术网

Javascript AngularJS模态不';t将创建的值返回到数组

Javascript AngularJS模态不';t将创建的值返回到数组,javascript,angularjs,twitter-bootstrap,Javascript,Angularjs,Twitter Bootstrap,我试图打开一个模式窗口,创建一个新记录,并将该记录与数据库中的所有记录一起放入数组 以下是打开模式的链接: <a href="" ng-click="openModalNew()">New Post (AngularJS)</a> 以及以下观点: <table class="table table-striped"> <tr> <th>Title</th> <th>Body<

我试图打开一个模式窗口,创建一个新记录,并将该记录与数据库中的所有记录一起放入数组

以下是打开模式的链接:

<a href="" ng-click="openModalNew()">New Post (AngularJS)</a>
以及以下观点:

<table class="table table-striped">
    <tr>
      <th>Title</th>
      <th>Body</th>
      <th>Starred</th>
      <th>Comments</th>
      <th></th>
      <th></th>
      <th></th>
    </tr>
    <tr ng-repeat="post in posts">
      ...

标题
身体
主演
评论
...
问题是,当我点击New Post链接时,会出现模式窗口,我输入信息并提交它-记录在数据库中创建,模式消失(这很好),但带有
posts
的表没有更新-没有添加此新记录

为什么呢?调用模式窗口的过程是否错误?我是否需要在某处添加
resolve
部分(我是AngularJS新手)?还是在模式窗口中使用
$scope
时工作不正确

我将非常感谢任何帮助,因为我不能使这项工作


多谢各位

我认为您必须通过模式关闭事件函数将作用域上的新数组传递回

$scope.$modalInstance.close($scope.posts);
从用户界面文档:

close(result) - a method that can be used to close a modal, passing a result

dismiss(reason) - a method that can be used to dismiss a modal, passing a reason

The event itself includes a parameter for the result/reason and a boolean parameter that indicates whether the modal is being closed (true) or dismissed.

plunkr here:

查询功能在哪里?你能展示一下吗?如果我没弄错的话,你一定在这里使用服务。你的帖子没有更新是什么意思?您在帖子中的帖子是否显示数据?您好
aintno12u
,谢谢您的评论。我更新了JS代码并添加了工厂
post in posts
返回数据,但是如果我通过模式窗口添加一条新记录,则此新记录不会添加到
posts
循环中,因此我在那里看不到此新添加的记录。
$scope.$modalInstance.close($scope.posts);
close(result) - a method that can be used to close a modal, passing a result

dismiss(reason) - a method that can be used to dismiss a modal, passing a reason

The event itself includes a parameter for the result/reason and a boolean parameter that indicates whether the modal is being closed (true) or dismissed.