从应用程序控制器传递的组件 属性 包含无效字符错误

component property passed from Application Controller contains invalid character error

我的应用程序控制器正在正确观察当前路径。我不知道问题是 属性 的传递还是控制器上 属性 的设置。

应用程序控制器:

import Ember from 'ember';

export default Ember.Controller.extend({
  currentUrl: null,
  currentPathDidChange: function() {
    return window.location.href;
    // alert(currentUrl);
  }.observes('currentPath').property('currentUrl')

});

模板:

<h2>page 1234</h2>
{{social-footer-login pageUrl=controllers.application.currentUrl}}

组件:

<h2>social footer component</h2>

<div id="footer-container">
  <div class="facebook">
    <span id="facebook-text">f</span>
  </div>
  <div class="linkedin">
    <span id="linkedin-text">in</span>q
  </div>
  <div class="fb">
    <div class="fb-share-button" data-href="https://developers.facebook.com/docs/plugins/" data-layout="button" data-size="small" data-mobile-iframe="false"><a class="fb-xfbml-parse-ignore" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=" + pageUrl>Share</a></div>
  </div>
</div>

错误: 字符串包含无效字符 setAttribute@http://localhost:4200/assets/vendor.js:16331:21

您的 pageUrl 变量需要以符合 Handlebars 的方式使用。不要做 Javascript 追加,而是直接在模板中使用 {{pageUrl}} 引用它:

<div class="fb-share-button" data-href="https://developers.facebook.com/docs/plugins/" data-layout="button" data-size="small" data-mobile-iframe="false"><a class="fb-xfbml-parse-ignore" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u={{pageUrl}}">Share</a></div>

那应该可以了。