Why say this error?: Error: [$compile:nonassign] Expression 'undefined' ... is non-assignable! AngularJS 1.5
Why say this error?: Error: [$compile:nonassign] Expression 'undefined' ... is non-assignable! AngularJS 1.5
我正在尝试创建一个用于在我自己的网站上创建“推文”的组件,当我尝试将内容写入文本区域时(无法写入任何内容)
我有这张显示错误的图片:
这是我在“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>
该组件不应该有绑定,因为我不需要发送任何数据,所以该组件正在尝试获取“tweet”,这就是错误。
这是正确的代码:
let EditorTweets = {
controller: EditorTweetsComponentCtrl,
templateUrl: 'components/tweets-helpers/editorTweets.html'
};
我正在尝试创建一个用于在我自己的网站上创建“推文”的组件,当我尝试将内容写入文本区域时(无法写入任何内容)
我有这张显示错误的图片:
这是我在“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>
该组件不应该有绑定,因为我不需要发送任何数据,所以该组件正在尝试获取“tweet”,这就是错误。
这是正确的代码:
let EditorTweets = {
controller: EditorTweetsComponentCtrl,
templateUrl: 'components/tweets-helpers/editorTweets.html'
};