How to Write an Event Handler in Phoenix

From ElixirBlocks
Jump to: navigation, search

Example


defmodule AppWeb.PageLive do
  use AppWeb, :live_view
  def mount(_params, _session, socket)  do
  {:ok, socket}
  end

  def handle_event("run", unsigned_params, socket) do
        IO.inspect "It works!"
        {:noreply, socket}
  end


  def render(assigns) do
    ~H"""
       <p phx-click="run">TEST</p>
  """
  end

end