I have defined a directive with the function createDOMWallPost in the scope. The function appends the newWallPost to the element which has the dynamic-wall attribute, if the http request goes well (server responds "OK")
angular.module('p2l.directives', []).directive('dynamicWall', function(){
return function(scope, element, attrs){
scope.createDOMWallPost = function(newWallPost){
$(element).append(newWallPost);
}
}
});
And in the controller I have
var newWallPost = $scope.newWallPost;
$http.post("/backend/newWallPost",
{
newWallPost : newWallPost
}).success(function(data){
if(data == "OK"){
$scope.createDOMWallPost(newWallPost);
}
});
This works, but it does not feel like its the right way to accomplish this. What other techniques could be used for this?
ng-repeatwith a array of wallposts would work. Why is directive required?