Attempting to create a table that can extract URL parameters from its grid-url
directive. The plan is to then use this extracted URL in the controller with $http
. However, it doesn't seem to be working as intended since the value always turns out to be undefined.
Here's how it's set up in the code:
<table class="table table-striped" grid-url="http://localhost/records/all">
...
</table>
And here's the relevant initialization section:
app.directive('gridUrl', function(){
return {
replace: true,
link: function(scope, element, attrs){
// Assigning the gridUrl property to the scope
scope.gridUrl = attrs.gridUrl;
}
}
});
app.controller('Ctrl', function($scope){
// Expecting to see http://localhost/records/all, but it ends up being undefined
console.log($scope.gridUrl);
});
This issue doesn't appear to relate to scope isolation. When using console.log($scope)
within the controller, it's surprising to see that $scope.gridUrl
does contain http://localhost/records/all
.
So, what might be causing the gridUrl
property to show as undefined in the controller?