I think you have wrong declarations.
For $watch
it should be look like:
native("$watch")
fun watch(watchExpression: String): () -> Unit = js.noImpl
native(“$watch”)
fun watch(watchExpression: String, listener: String): () -> Unit = js.noImpl
native(“$watch”)
fun watch(watchExpression: String, listener: String, objectEquality: Boolean): () -> Unit = js.noImpl
native(“$watch”)
fun watch<T>(watchExpression: String, listener: (newValue: T, oldValue: T, scope: Scope) -> Any): () -> Unit = js.noImpl
native(“$watch”)
fun watch<T>(watchExpression: String, listener: (newValue: T, oldValue: T, scope: Scope) -> Any, objectEquality: Boolean): () -> Unit = js.noImpl
native(“$watch”)
fun watch(watchExpression: (scope: Scope) -> Any, listener: String): () -> Unit = js.noImpl
native(“$watch”)
fun watch(watchExpression: (scope: Scope) -> Any, listener: String, objectEquality: Boolean): () -> Unit = js.noImpl
native(“$watch”)
fun watch<T>(watchExpression: (scope: Scope) -> Any, listener: (newValue: T, oldValue: T, scope: Scope) -> Any): () -> Unit = js.noImpl
native(“$watch”)
fun watch<T>(watchExpression: (scope: Scope) -> Any, listener: (newValue: T, oldValue: T, scope: Scope) -> Any, objectEquality: Boolean): () -> Unit = js.noImpl
For directive
i wrote:
native fun directive(name: String, def: (Timeout)->Any): (scope: Scope, elem: Elem, attrs: Attrs) -> Unit = js.noImpl
But I'm sure that `def` has the wrong type. Unfortunately I am not familiar with AngularJS for fix it.
And now you can write:
directive("todoFocus") { (timeout: Timeout) ->
{(scope: Scope, elem: Elem, attrs: Attrs) ->
watch<Boolean>(attrs.todoFocus) { (newVal, oldVal, scope) ->
if(newVal) {
timeout({ elem[0].focus() }, 0, false);
}
}
}
}
Next, you can add helper function postLink
like:
inline fun postLink(f: (scope: Scope, elem: Elem, attrs: Attrs) -> Unit) = f
then:
directive("string") { (timeout: Timeout) ->
postLink {(scope, elem, attrs) -> // <-------------------------------------------- without type declaration here
watch<Boolean>(attrs.todoFocus) { (newVal, oldVal, scope) ->
if(newVal) {
timeout({ elem[0].focus() }, 0, false);
}
}
}
But now it add unnecessary function call in generated js.