Q:

How to get $attrs data of children DOM in a controller?

Let say I have a controller and many children DOMs with their own data attributes.
<!DOCTYPE html>
<html ng-app="plunker">

  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <script>document.write('<base href="' + document.location + '" />');</script>
    <link rel="stylesheet" href="style.css" />
    <script data-require="angular.js@1.2.x" src="https://code.angularjs.org/1.2.16/angular.js" data-semver="1.2.16"></script>
    <script src="app.js"></script>
  </head>

  <body ng-controller="MainCtrl">
    <p data-test-val='Brian'>Hello {{name}}!</p>
  </body>

</html>

I want to access to the data-test-val like this
var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope, $attrs) {
  $scope.name = $attrs.testVal;
});

However, it does not seem to work as name is empty.
http://plnkr.co/edit/V1Leit8U7r2k4CZDGaGa?p=preview
How to access any data attribute in children DOM of the same scope?
Thanks.

A:

you're messing up controllers with directives in terms of attribute acquiration.
directive:
.directive('directiveName', function() {
    return {
        link: function($scope, $elem, $attrs) {
            // get $attrs stuff here
        }
    }
});

