I’m writing my first LiveView App, I followed the Installation Guide and I defined the route in router.ex like this live "/thermo", ThermoLive then wrote my code like this:
defmodule ThermoWeb.ThermoLive do
use Phoenix.LiveView
alias ThermoWeb.ThermoView
def mount(_params, _,socket) do
{:ok, assign(socket, :temp, 32)}
end
def render(assigns) do
~L"""
Current temperature: <%= @temp %>
<button phx-click="set_temp">Set</button>
"""
end
def handle_event("set_temp", _,socket) do
{:noreply, assign(socket, :temp, 24)}
end
end
However, when I click on the button nothing happens? What did I do wrong?
Thanks in advance!
As @sfusato has suggested. If you don’t see your assets being loaded (css, js) and your app header is missing, that means you haven’t set a live or root layout as the documentation suggests. You either have to create a live.html.leex and copy/paste the header from your app.html.eex + add flashes and content to your body as the example bellow.