Angularjs通过check单选按钮将数据绑定到其他表,并在单击按钮后更新
根据你提供的一点信息,我想尝试一下:Angularjs通过check单选按钮将数据绑定到其他表,并在单击按钮后更新,angularjs,Angularjs,根据你提供的一点信息,我想尝试一下: 您能否在控制器中定义$scope和函数?您想实现什么?{{song.name}{{song.artist}{{song.genre}{{song.price}}我想使用ngmodel的单选按钮,当我点击单选按钮时,数据加载到其他表。我更新数据,但只在单击按钮更新后更新,而不是直接绑定除非我误解了您的意图,angular.copy不会直接绑定,而是复制对象$scope.edit_song=歌曲将是直接绑定。我尝试使用$scope.selectedSong[in
您能否在控制器中定义$scope和函数?您想实现什么?{{song.name}{{song.artist}{{song.genre}{{song.price}}我想使用ngmodel的单选按钮,当我点击单选按钮时,数据加载到其他表。我更新数据,但只在单击按钮更新后更新,而不是直接绑定除非我误解了您的意图,angular.copy不会直接绑定,而是复制对象$scope.edit_song=歌曲将是直接绑定。我尝试使用$scope.selectedSong[index]=angular.copy$scope.editSong;但是我不知道为什么当我点击单选按钮时,它仍然不显示数据,数据没有加载到另一个表中。你看了我的小提琴吗$scope.selectedSong不需要[索引]
<table>
<tr>
<td><input type="radio" name="groupName" value="song" ng-model="$parent.selectedSong"/></td>
<td>{{song.name}}</td>
<td>{{song.artist}}</td>
<td>{{song.genre}}</td>
<td>{{song.price}}</td>
<td>
<input type="button" value="Delete" ng-click="deleteItem(song.id)" />
</td>
<td>
<input type="button" value="View" ng-click="go('OneSong', song)" />
</td>
</tr>
</table>
<table border="1">
<tr><td id="Td1">Correct Table</td></tr>
<tr>
<td>Name: </td>
<td><input type="text" ng-model="editItem.name"/></td>
</tr>
<tr>
<td>Artist: </td>
<td><input type="text" ng-model="editItem.artist"/></td>
</tr>
<tr>
<td>Genre: </td>
<td><input type="text" ng-model="editItem.genre"/></td>
</tr>
<tr>
<td>Price: </td>
<td><input type="text" ng-model="editItem.price"/></td>
</tr>
<tr>
<td colspan="2">
<!--<input type="button" value="Insert "ng-click="addItem()"/>-->
<a href="#/AddNewSong">Add New Song</a>
<input type="button" value="Update" ng-click="updateItem()"/>
<input type="button" value="Cancel" ng-click="cancel()"/>
</td>
</tr>
</table>
var app = angular.module('songApp',[]);
app.controller('SongCtrl',function($scope) {
$scope.edit_song = {};
$scope.song = [
{name:'Heartbreaker',artist:'Led Zeppelin',genre:'Rock',price:'.99'},
{name:'War Pigs',artist:'Black Sabbath',genre:'Rock',price:'.99'}
];
$scope.applySong = function(song) {
$scope.edit_song = angular.copy(song);
$scope.edit_song.song_index = $scope.song.indexOf(song);
};
$scope.saveSong = function() {
var idx = $scope.edit_song.song_index;
$scope.song[idx] = $scope.edit_song;
$scope.cancelSong();
};
$scope.cancelSong = function() {
$scope.edit_song = {};
};
});