0

I want to mimic something that I have done with JQuery using AngularJS.

Below is the fiddle for it.

Three things I have done here.

  1. Find the last element of the right column.
  2. Pickup the attribute 'data-color' from it
  3. Assign the value of the attribute as a class to the 'right-col'
1
  • @georgegeawg: The link is already there in the question. The text "fiddle" has a link to it. The question is already been answered too. Commented Feb 1, 2016 at 13:52

2 Answers 2

1

Try this JSFiddle: https://jsfiddle.net/ubqrah1w/

It uses an angular directive.

.directive('lastColor', function () {
  return {
    restrict: 'A',
    link: function ($scope, $element, $attrs) {
    $element.addClass(angular.element($element[0].querySelector('.items:last-child')).attr('data-color'));
    }
  }
  });
Sign up to request clarification or add additional context in comments.

2 Comments

Well doesnt work if i add the JS in a seperate file.. or in fiddle in the JS page.jsfiddle.net/ubqrah1w/1
you have to load the javascript in the body, check this jsfiddle.net/yLtq1296
1

This can be done by angular'js directive (re-usable component) moreover angular has jqlite (jQuery library), as below.

directives:

app.directive('dynamicColor',dynamicColor);

    dynamicColor.$inject = [];

    function dynamicColor(){

      return{
        restrict:'A',
        link:function(scope,element,attrs){
          element.css('background-color',attrs.dynamicColor);
        }
      }

    }

https://plnkr.co/edit/Op5fI5oFQku07tkebBcg?p=preview

1 Comment

thanks a lot :) ur right.. but the above one was to the point.. but thanks a lot dude..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.