json - Angular Json 管道类型错误 : Converting circular structure to JSON

标签 json angular angular-pipe

我一直在尝试遵循 angular course 并在使用 ngform 时遇到以下错误:

core.js:6237 ERROR TypeError: Converting circular structure to JSON --> starting at object with constructor 'TView' | property 'blueprint' -> object with constructor 'LViewBlueprint' --- index 1 closes the circle



以下是模板html:
    <div class="container">
      <h2>User Settings</h2>
      <form #form="ngForm">
        <div class="form-group">
          <label for="name">Name</label>
          <input id="name" name="name" class="form-control" placeholder="Name" />
        </div>
        <div class="form-check form-group">
          <input class="form-check-input" type="checkbox" value="" id="emailOffers">
          <label class="form-check-label" for="emailOffers">
                Email Special Offers
                </label>
        </div>
        <h5>User Interface Style</h5>
        <div class="form-group">
          <div class="form-check">
            <input class="form-check-input" type="radio" name="InterfaceStyle" id="lightInterface" value="Light" checked>
            <label class="form-check-label" for="lightInterface">
                    Light
                    </label>
          </div>
          <div class="form-check">
            <input class="form-check-input" type="radio" name="InterfaceStyle" id="mediumInterface" value="Medium">
            <label class="form-check-label" for="mediumInterface">
                    Medium 
                    </label>
          </div>
          <div class="form-check">
            <input class="form-check-input" type="radio" name="InterfaceStyle" id="darkInterface" value="Dark">
            <label class="form-check-label" for="darkInterface">
                    Dark 
                    </label>
          </div>
        </div>
        <div class="form-group">
          <label for="subscriptionType">Subscription Type</label>
          <select class="form-control" id="subscriptionType">
            <option>Monthly</option>
            <option>Annual</option>
            <option>Lifetime</option>
          </select>
        </div>
        <div class="form-group">
          <label for="notes">Notes</label>
          <textarea class="form-control" id="notes" rows="3"></textarea>
        </div>
        <button class="btn btn-primary">Save</button>
      </form>
    </div>
    {{ form | json }}

最佳答案

它会向您抛出此错误,因为它对控件有一些循环依赖,因此它会向您抛出此错误。您可以尝试打印它的值。

要打印整个表单对象,您可以使用

 {{form.value | json}}

Stackblitz 链接 => https://stackblitz.com/edit/angular-6-template-driven-form-validation-prcrob

关于json - Angular Json 管道类型错误 : Converting circular structure to JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61577473/

相关文章:

html - border-color 和 box-shadow 颜色在我更改 css 代码后不会改变

angular - 以编程方式使用 AsyncPipe - Angular 2

angular - Typescript 将时间戳转换为 mm-dd 格式

ios - Angular 6 日期管道在 iPhone safari 浏览器上不显示任何内容

json - 如果字典中有多个 json 字段同名,如何获取值?

ios - 如何将 Javascript 日期转换为 iOS 日期格式

javascript - 如何 Hook 库函数(Golden Layout)并调用其他方法

javascript - 如何使用 Angular 获取典型的 json 数据

ios - Swift 2 SwiftyJSON API 数据到 UITableView

javascript - 在系统浏览器中打开来自 JSON 的链接 - Cordova