Dmitrij Kostyushko Dmitrij Kostyushko - 1 year ago 54
AngularJS Question

Angular directive attribute does not bind with the controller

I have a directive called orders-list and i need to bind the object currentOrder inside the controller with object inside the loop that was clicked on;

app.controller("receivedOrders", ['$scope', 'orders', 'Order', 'currentOrder', function ($scope, orders, Order, currentOrder) {
$scope.currentOrder = null;
$scope.orders = orders['content'];

app.directive("ordersList", function () {
return {
restrict: 'E',
templateUrl: 'templates/orders_list.html',
scope: {orders: '=', currentOrder: '='},
controller: ['$scope','$attrs', function ($scope, $attrs) {
$scope.selectOrder =function(order){
//some other functions

//directive definition
<orders-list current-order="currentOrder" orders="orders"></orders-list>

//directive body
<order ng-repeat="order in orders|filter:query|"
order="order" ng-click="selectOrder(order)"></order>

-------- Changes---------

So ok now i pass the function selectOrder to the inner directive order, and invoke the selectOrder function from it`s scope, but it still does not work =(

app.directive('order', function () {
return {
restrict: "E",
templateUrl: '/templates/order.html',
scope: {
order: '=',

<md-list-item order-click="orderClick({order:order})" class="md-3-line">

<order ng-repeat="order in orders|filter:query|"
order="order" order-click="selectOrder(order)"></order>

Answer Source