<form> <div> <input type="text" [(ngModal)]="value" > </div> <div> <button>保存</button> <button>取消</button> </div> </form>
会报错
If ngModel is used within a form tag, either the name attribute must be set or the form
解决办法:
在绑定了ngModel的地方加入name属性即可
<form> <div> <input type="text" [(ngModal)]="value" name="fieldName"> </div> <div> <button>保存</button> <button>取消</button> </div> </form>