如何使用symfony2和angularjs对删除操作进行模态确认

时间:2015-10-21 19:28:13

标签: angularjs symfony angularjs-scope

这是我的控制器Symfony:

$em = $this->getDoctrine()->getManager();
$advert = $em->getRepository('OCPlatformBundle:Advert')->find($id);
if ($advert == null) {
  throw $this->createNotFoundException("L'annonce d'id ".$id." n'existe pas.");
}
      $em->remove($advert);
      $em->flush();

      $request->getSession()->getFlashBag()->add('notice', 'Annonce bien enregistrée.');

      return $this->redirect($this->generateUrl('oc_platform_view', array('id' => $advert->getId())));
    }


  }

和枝条

{% for advert in adverts %}
        <li>{{ advert.name|e }}</li>
<a href="{{ path('delete_route_name', {'id': advert.id }) }}">Delete</a>
    {% endfor %}

请帮助,我不知道如何使angularJs显示删除操作的模态确认并刷新我的视图页

1 个答案:

答案 0 :(得分:4)

您可以在javascript中执行此操作:

<a href="javascript:void(0)" onclick="if(confirm('Are you sure?')){window.location='{{ path('delete_route_name', {'id': advert.id }) }}';}">delete</a>