Interactive SVGs in AngularJS

Interactive SVGs in AngularJS

My latest project has been utilizing my art degree (wait, what? An art degree is useful as a software engineer? Surprisingly, YES). Using Inkscape, I created a very customized keyboard as an SVG (Scalable Vector Graphic). There were two things I had to do with this file:

  1. Embed the SVG into a view inside my AngularJS application.
  2. Each key element/node needed an attribute so when it was pressed, something would happen. Because, you know, what good is a key if you can’t click on it?

As I discovered, these two tasks are a lot harder than they should be. Putting an SVG into a view is as simple as making the file path the of an in the HTML. You can add an to the , but that only works if you want the entire SVG to be clickable. I wanted interactivity inside the SVG itself. Adding as an attribute within a node in the SVG file will NOT work! To do what I wanted, I neede to use directives to embed the SVG in the view and attach a attribute to each of my keys.

I found this site that had an interactive map and thought, “Hey, that’s kind of similar to what I want to do!” So, using their insights, I was able to make a clickable keyboard within my AngularJS application. Here’s how I did it:

Read more by clicking here.

To view or add a comment, sign in

More articles by Lori Becker 🇺🇦

  • My Three Year Anniversary at Clutch

    It used to be true that people worked at one company for the rest of their lives. My father worked at one company from…

    1 Comment
  • A Change of Scenery

    I started a new job in the beginning of April. My first job as a software engineer, though, will always have a special…

  • An Ergonomic Keyboard That Works!

    So, how’s my new Kinesis FreeStyle2 keyboard? Is it as ergonomical as I need it to be relieve my RSI symptoms? Would it…

  • Time For A New Keyboard

    I’ve been thinking a lot about ergonomics lately. A few weeks ago, I thought I was dreaming as I looked down and saw…

  • DropWizard Metrics 101

    Photo courtesy of nathanmac87. My most recent project at work has been to utilize DropWizard metrics to gather…

  • I Graduated. Now What?

    It’s official. I’ve earned my Master’s in Computer and Information Technology.

    2 Comments
  • A Year And A Half Later

    I’ve started my last course before I graduate in May. Of course, in typical Lori-fashion, I decided to take one of the…

    3 Comments
  • We're Not Serious About Software Security

    Photo courtesy of www.perspecsys.

    2 Comments
  • Why I Type in Dvorak

    If you do a considerable amount of typing on a daily basis and have experienced stiffness or pain in the joints of your…

  • From Shakespeare To Java

    A little more than a ago, I was a high school English teacher. I walked around a classroom supervising activities to…

Explore content categories