Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <ul ng-controller="mainCtl">
- <li inner="{item: item}" ng-repeat="item in items" ng-class="{sel: inner.selected}">
- {{ item.Name }}
- </li>
- </ul>
- directive('inner', [
- function() {
- return {
- restrict: 'A',
- scope: {
- inner: '='
- },
- link: function(scope, element, attr) {
- scope.inner.selected = false;
- element.bind('click', function(e) {
- scope.inner.selected = !scope.inner.selected;
- });
- }
- };
- }]);
- <ul ng-controller="mainCtl">
- <li ng-click="selected=!selected" ng-repeat="item in items" ng-class="{sel: selected}">
- {{ item.Name }}
- </li>
- </ul>
- angular.module('test', []).
- controller('mainCtl', ['$scope',
- function($scope) {
- $scope.items = [{Name: 'obj1'}, {Name: 'obj2'}];
- console.log($scope);
- }]).
- directive('inner', [
- function () {
- return {
- restrict: 'A',
- scope: {
- inner: '='
- },
- link: function (scope, element, attr) {
- var el = angular.element(element);
- el.on('click', function (a, b, c) {
- if (el.hasClass('sel')) {
- el.removeClass('sel');
- } else {
- el.addClass('sel');
- }
- });
- }
- };
- }]);
- app.service('selection', [function(){
- function selection(array){
- //constructor function that attaches or creates the selection logic for the array
- }
- this.create = function(input){
- return new selection(input);
- }
- }]);
- app.controller('myCtrl', ['selection', '$scope', function(selection, $scope){
- $scope.array = [{...},{...}];
- //Creates a selection from the array
- $scope.selection=selection.create($scope.array);
- }])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement