angularjs - Updating $scope in an Angular directive -
i m using following, after frustration , googling cannot data_banks
item update in $scope
after $resource
marketplace.buy
has been loaded successfully;
myapp.directive('marketplacebuy', function() { return { restrict: 'a', controller: ['$scope', "$timeout", "marketplace", "notification", "databank", function ($scope, $timeout, marketplace, notification, databank) { $scope.dooo = function(attrs) { marketplace.buy({'item': attrs.itemid}, function(){ databank.query({word: "databanks"}, function(data){ $scope.data_bank = data.data; }); }, function(resp){ notification.error(resp.data.message); }); } }], link: function ($scope, element, attrs) { element.bind('click', function () { $scope.dooo(attrs); }); } }; });
using $scope.$apply()
errors.
edit
the original data_bank
loaded so
mycontrollers.controller('locationlistctrl', ['$scope', 'databank', function($scope, databank) { $scope.data_bank = databank.query({word: "databanks"}); });
and bound view so
<body ng-cloak> <div ng-view> <div ng-repeat="blue_print in data_bank.blue_prints">{{ blue_print.name }}</div> </div> </body>
finally controller loaded using route
myapp.config(['$routeprovider', '$httpprovider', function($routeprovider, $httpprovider) { $httpprovider.interceptors.push('myinterceptor'); $routeprovider. when('/locations', { templateurl: "/bundles/app/partials/locations.html", controller: 'locationlistctrl' }) }]);
follow model.value rule.
$scope.data_bank.data = data.data;
in template, obviously, use {{data_bank.data}}
Comments
Post a Comment