javascript - angular can't access directive property -
i have following app directive:
(function() { var app = angular.module('myfeed', []); app.directive("feedlist", function(){ console.log('in feed list directive'); return { restrict: 'e', templateurl: "/static/angular/phone-list/feed-list.template.html", cotrolleras: 'mycontroller', controller: function($http){ var data = $.param({ grant_type: 'password', username: 'test', password: 'test', client_id:'test', client_secret:'test', }); var config = { headers : { 'content-type': 'application/x-www-form-urlencoded;charset=utf-8;' } } $http.post('/o/token/', data, config) .success(function (data, status, headers, config) { access_token = data['access_token']; console.log(access_token); $http({method: 'get', url: 'api/posts/', headers: {'authorization': 'bearer '+access_token}}).then(function(response) { this.posts = response.data; }); }) .error(function (data, status, header, config) { $scope.responsedetails = "data: " + data + "<hr />status: " + status + "<hr />headers: " + header + "<hr />config: " + config; }); var header = { headers : { 'authorization': 'bearer '+self.access_token } } }, } }); })();
my directive in index.html looks this:
<feed-list></feed-list>
the template looks this:
<li ng-repeat="post in mycontroller.posts>{{post}}</li>
how can <feed-list>
display posts set in this.posts
?
the scope of changes in javascript functions. keep reference a
var mycontroller = this;
at beginning of controller's constructor function , use
mycontroller.posts = response.data;
rather than
this.posts = response.data;
in http callback function.
Comments
Post a Comment