Hi All. I know directives and scopes have been covered quite a lot all over
the internet but I haven't found a real example for what I want.
I want to be able to access the scope from my main controller inside of a
directive. Most of the posts I seen on this have to do with actually
accessing attributes or values that are related to the directive it self.
In this case what I want to do is grab some data that I got from the back
end in my controller and then display that as part of a template in a
directive...
Here is sample code...
App.js
'use strict';
var mintApp = angular.module('mintApp', ['ngRoute', 'ngProvider']);
mintApp.config(function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl: '../../MINT/views/main.php',
controller: 'MainController'
})
.when('/client/signup', {
templateUrl: '../MINT/views/client-membership.php',
controller: 'FormController'
})
.otherwise({redirectTo: '/'});
});
Controller...
mintApp.controller('FormController', function($scope, $http) {
$scope.providerData = {};
$http.get('../MINT/scripts/php/get_providers.php')
.success(function(data) {
// console.log(data);
$scope.providerData = data;
});
});
Directive
'use strict';
angular.module('ngProvider', []).directive('providerList', ['$location',
function($location) {
return {
restrict: 'A',
replace: true,
template: '<h1>$scope.providerData</h1>'
};
}]);
Notice the $scope.providerData value I want to use in my template but how
do I access this WITHOUT using a link function? and even if I do use a link
function how?
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.