【问题标题】:Why say this error?: Error: [$compile:nonassign] Expression 'undefined' ... is non-assignable! AngularJS 1.5为什么说这个错误?:错误:[$compile:nonassign] Expression 'undefined' ... is non-assignable! AngularJS 1.5
【发布时间】:2020-09-24 18:37:45
【问题描述】:

我正在尝试在我自己的网站中创建一个用于创建“推文”的组件,并且当我尝试将某些内容写入 textarea 时(无法写入任何内容)

我有这张显示错误的图片:

这是我在“editorTweets.component.js”中的代码:

class EditorTweetsComponentCtrl {
    constructor($scope, $state, User, Tweets){
        "ngInject";
        this._Tweets = Tweets;
        this._$state = $state;
        this._$scope = $scope;
        
        this.currentUser = User.current;
        console.log(this.currentUser);


        this.tweet = {
          body: ''
        }
        
        
    }

    submit() {
        console.log(this.tweet.body);

      }

}

let EditorTweets = {
    bindings: {
        tweet: '='
    },
    controller: EditorTweetsComponentCtrl,
    templateUrl: 'components/tweets-helpers/editorTweets.html'
};

export default EditorTweets;

和 .html 视图:

<div class="container-editor-tweets">
    <div class="left-editor-tweets">
        <img ng-src="{{$ctrl.currentUser.image}}" alt="Img-User"/>
    </div>

    <div class="right-editor-tweets">
        <div class="editor-tweet-body">
            <textarea name="tweet_msg" id="tweet_msg" placeholder="Whats going on?..." ng-model="$ctrl.tweet.body"></textarea>
        </div>
        <div class="editor-tweet-options">
            <button class="btn-submit-tweet" type="button" ng-click="$ctrl.submit()">Tweet</button>
        </div>
    </div>
</div>

【问题讨论】:

  • 您是否尝试过将推文附加到范围而不是像scope: { 'tweet': '='}这样的绑定

标签: javascript node.js angularjs


【解决方案1】:

组件不应该有绑定,因为我不需要发送任何数据,所以组件试图获取“tweet”,这就是错误。

这是正确的代码:

let EditorTweets = {
    controller: EditorTweetsComponentCtrl,
    templateUrl: 'components/tweets-helpers/editorTweets.html'
};

【讨论】:

    猜你喜欢
    • 2016-05-30
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 2022-01-26
    • 2019-01-15
    • 1970-01-01
    • 2021-09-10
    • 2015-06-22
    相关资源
    最近更新 更多