type Msg
= NoOp
| RequestDate
| ReceiveDate Date
| UpdateYouTubeUrl YouTubeUrl
-- -
root : Maybe YouTubeUrl -> Html Msg
root youTubeUrl =
case youTubeUrl of
Just youTubeUrl ->
div []
[ player youTubeUrl
, urlInput
]
Nothing ->
urlInput
player : YouTubeUrl -> Html Msg
player youTubeUrl =
h1 [] [ text ("YouTube player for " ++ youTubeUrl ++ " goes here") ]
urlInput : Html (YouTubeUrl -> Msg)
urlInput =
input
[ placeholder "(Enter a YouTube embed URL and hit <Enter>)"
, onSubmit UpdateYouTubeUrl
]
[]
-- TYPE MISMATCH ---------------------------------- ./src/YouTubePlayer/View.elm
The 1st and 2nd entries in this list are different types of values.
28| [ player youTubeUrl
29|> , urlInput
30| ]
The 1st entry has this type:
Html (Msg)
But the 2nd is:
Html (YouTubeUrl -> Msg)
Hint: It looks like a function needs 1 more argument.
Hint: Every entry in a list needs to be the same type of value. This way you
never run into unexpected values partway through. To mix different types in a
single list, create a "union type" as described in:
<http://guide.elm-lang.org/types/union_types.html>
Detected errors in 1 module.
エラーは、問題は、私は
[ Html Msg
, Html (YouTubeUrl -> Msg)
]
のリストを持っていることであることはかなり明白です。.. Elmのリストが同質である必要があるが、私が理解していないのはHtml (YouTubeUrl -> Msg)
がurlInput
の型シグニチャである理由である。私はそれが私の使用と何かを持っていることを集めるonSubmit
。
私はエルムの初心者ですので、私は何が間違っているのか分かりません。 Elm Guide bookには、私が見たHtml (a -> Msg)
のようなタイプの例はありません。
onSubmit : msg -> Attribute msg
あなたはそれを単一のパラメータを取るコンストラクタ、UpdateYouTubeUrl
を、渡している:
elm 0.18
ああ、違いはわかりました。 'onSubmit'をフォームでラップしようとしていました。なぜなら、私は' onInput'を起動するのではなく、Enterキーを押したいからです。最も簡単な方法は 'onSubmit'にフックすることだと考えました。 – neezer
'onSubmit'でこれを行う方法の例を投稿してもよろしいですか? – neezer