事件

2014-05-20 54 views
0
angular.module('InvoicerApp') 
    .directive('invoice', function() { 
     return { 
      restrict: 'E', 
      templateUrl: 'templates/invoice-directive.html', 
      scope: true 
     }; 
    }); 

發票directive.html事件

 <div class="row"> 
      <div class="col-md-1"> 
       <input type="text" ng-model="invoice.product.tax" class="form-control input-sm" placeholder="TVA"> 
      </div> 
      <div class="col-md-1"> 
       <select type="text" ng-model="invoice.product.includeTax" class="form-control input-sm" placeholder="TVA?"> 
        <option value="true" selected>Include TVA</option> 
        <option value="false">Nu include TVA</option> 
       </select> 
      </div> 
      <div class="col-md-1"> 
       <button type="text" ng-model="invoice.product.add" class="btn btn-primary btn-sm" ng-click="invoiceAddProduct()"> 
        <span class="glyphicon glyphicon-plus"></span> 
       </button> 
      </div> 
     </div> 

控制器

$scope.invoice = {}; 
    $scope.invoice.products = []; 
    $scope.client = {}; 


    $scope.invoiceAddProduct = function() { 
     console.log("HELLO");  
    }; 

invoiceAddProduct沒有從該指令模板內被解僱。我如何從控制器的指令模板內部訪問模型?

+0

能否請您發表您的HTML,你必須包括指令? – Ritesh

+0

Sherlock

+0

謝謝:)我剛剛發現我沒有發起控制器... :) – Sherlock

回答

1

看起來您的指令的範圍並未落在您的控制器的範圍之內。請檢查您的HTML。看看小提琴,我是從一個指令調用控制器功能:

演示:jsfiddle.net/X7Fjm/2/