/*style.css*/.container { margin-top: 40px;}.glyphicon { padding-top: 8px;}.glyphicon-remove { color: red;}.glyphicon-ok { color: green;}.info-block { padding-left: 0px;}
// controllers.jsangular.module('firstMoudule', []) .service('hobbyDataService', function() { return { hobbies: [1, 3] } }) .controller('firstController', ['$scope', 'hobbyDataService', function($scope, hobbyDataService) { $scope.hobbies = [{ id: 1, name: 'coding' }, { id: 2, name: 'soccer' }, { id: 3, name: 'reading' }, { id: 4, name: 'sleeping' }]; $scope.hobbyData = hobbyDataService; $scope.toggleHobbySelection = function(id) { var index = $scope.hobbyData.hobbies.indexOf(id); if (index === -1) { $scope.hobbyData.hobbies.push(id); } else { $scope.hobbyData.hobbies.splice(index, 1); } console.log($scope.hobbyData.hobbies); } }]);
页面效果