为什么我无法将价值绑定到我的自定义指令?

时间:2017-06-22 19:20:55

标签: angular

我创建了一个自定义指令来验证我在表单上的输入:

package main

import (
    "fmt"
)

func main() {
    Yell(&Person{ Yeller: yeller("%s!!!\n") }, "Nooooo")
    Yell(&RoboticVoice{Yeller: twiceYeller("*** %s ***")}, "Oh no")
    Whisper(&Person{ Whisperer: whisperer("Sssssh! %s!\n")}, "...")
    Whisper(&RoboticVoice{ Whisperer: whisperer("Sssssh! %s!\n")}, "...")
}

type Yeller interface {
    Yell(message string)
}

func Yell(y Yeller, message string) {
    y.Yell(message)
}

type Whisperer interface {
    Whisper(message string)
}

func Whisper(w Whisperer, message string) {
    w.Whisper(message)
}

type Person struct {
    Yeller
    Whisperer
}

type RoboticVoice struct {
    Yeller
    Whisperer
}

func (voice *RoboticVoice) Yell(message string) {
    fmt.Printf("BEEP! ")
    voice.Yeller.Yell(message)
    fmt.Printf(" BOP!\n")
}

func (voice *RoboticVoice) Whisper(message string) {
    fmt.Printf("Error! Cannot whisper! %s\n", message)
}

type yeller string

func (y yeller) Yell(message string) {
    fmt.Printf(string(y), message)
}

type twiceYeller string

func (twice twiceYeller) Yell(message string) {
    fmt.Printf(string(twice+twice), message, message)
}

type whisperer string

func (w whisperer) Whisper(message string) {
    fmt.Printf(string(w), message)
}

如果我传递任何值而没有绑定到我的自定义指令,它工作正常,但是当我使用biding时,它会抛出以下错误:

  

未捕获错误:模板解析错误:无法绑定到'minNumber'   它不是'输入'的已知属性。

这是我使用自定义指令的地方:

  #loading {
   display: block;
   width: 100%;
   height: 100%;
   position: absolute;
   background-image: url('loading.gif');
   background-position: center;
   overflow: hidden;
 }

有人可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:2)

你试过吗

@Input()
minNumber: number;

而不是使用构造函数?

同样......我注意到当你有一个这样的验证器需要输入时,你必须跳过几个环,以便在minNumber改变时重新运行验证。看看MaxLengthValidator,了解如何继续。

相关问题