Why say this error?: Error: [$compile:nonassign] Expression 'undefined' ... is non-assignable! AngularJS 1.5

Viewed 43

I'm trying to create a component for create "Tweets" in my own website, and when I try to write something into textarea (can't write anything)

I have this image which shows the error:

AngularJS 1.5 error

And that's my code in "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;

and the .html view:

<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>

1 Answers

The component shouldn't have bindings, because I don't need to send any data, so the component is trying to get "tweet" and that's the error.

This is the correct code:

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