저는 새로운 기능이며 add to list 기능을 구현하려고합니다. 나는 몇 가지 질문이목록에 기능 목록에 추가
- 이유 정의되지 않은
- 때문에 변수 리프팅에
sendChat()
호출에 사용할 수newChat
가console.log
반환$scope.newChat
의 않습니다.
템플릿
<ion-list>
<ion-item class="item-remove-animate item-avatar item-icon-right" ng-repeat="chat in chats" type="item-text-wrap" href="#/tab/chats/{{chat.id}}">
<img ng-src="{{chat.face}}" >
<h2>{{chat.name}}</h2>
<p>{{chat.lastText}}</p>
<i class="icon ion-chevron-right icon-accessory"></i>
<ion-option-button class="button-assertive" ng-click="remove(chat)">
Delete
</ion-option-button>
</ion-item>
<ion-item >
<form ng-submit="sendChat(newchat)"> <!-- this line in question 2 -->
<label class="item item-input">
<input type="text" placeholder="What do you need to do?" ng-model="newchat.lastText">
<button type="submit" class="button button-right button-positive">Send</button>
</label>
</div>
</form>
</ion-item>
</ion-list>
컨트롤러
.controller('ChatsCtrl', function($scope, Chats) {
$scope.chats = Chats.all();
$scope.remove = function(chat) {
Chats.remove(chat);
}
$scope.sendChat = function(newchat){
Chats.set(newchat);
console.log($scope.newchat); //this line in question 1
newchat.lastText = "";
}
})
'Chats.set'이란 무엇입니까? '.set' 메소드의 구현은 여러분의 질문에 필수적입니다. –
그것은 공장입니다. – aWebDeveloper
이온 항목이 새 범위를 만듭니다. 은 이온 항목 수준에서 newchat을 만들 수 있도록 그리고 당신은, 당신의 컨트롤러 범위에 newchat를 초기화하지 않았습니다. 따라서 컨트롤러 범위를 통해 액세스 할 수 없습니다. 따라서 컨트롤러 범위에서 newchat에 액세스하려면 컨트롤러 범위에 빈 newchat 객체를 만듭니다. 그러면 이온 항목에 의해 공유됩니다. 그리고 당신은 당신의 컨트롤러 범위에서 그것을 가질 것입니다. – dhavalcengg