我正在尝试在 AngularJS中显示用户列表
每个人都是具有自定义组件元素的用户组件将有两个按钮
第一个必须从 DOM 中删除组件元素(并销毁观察者等),但不要更改用户列表。
第二个必须从列表中删除组件和用户
// app.controller.js
// ///////////////////
(function() {
'use strict';
angular
.module('app')
.controller('MainController', MainController);
function MainController( $log, $scope ) {
var vm = this;
vm.title = "I'm the Parent controller";
vm.users = [
{id: 1, name: 'Rob', color: 'slategrey'},
{id: 2, name: 'Ned', color: 'snow'},
{id: 3, name: 'Ramsey', color: 'palevioletred'}
];
}
})();
// Component Controller
// /////////////////////////
(function() {
'use strict';
angular
.module('app')
.controller('ComponentController', ComponentController);
function ComponentController() {
var $ctrl = this;
$ctrl.removeMe = removeMe;
$ctrl.removeMeFromAll = removeMeFromAll;
function removeMe(){
//angular.element.remove();
//$ctrl.$destroy();
// Magic goes here
// .............
}
function removeMeFromAll(userID) {
// Magic goes here
// .............
}
}
})();
我一直在搜索并查看用于带有链接元素的指令的方式,但无法弄清楚如何在此处应用。