2014-11-04 3 views
11

में समारोह ट्रिगर नहीं करता मैं एक plunker यहाँ बनाया है:एनजी-क्लिक करें नियंत्रक

जब मैं दिन को ध्यान में रखते ui ग्रिड के एक सेल में क्लिक करें, फिर कुछ नहीं होता। मुझे उम्मीद थी कि परीक्षण समारोह निष्पादित किया गया है और पाठ 'परीक्षण' के साथ एक चेतावनी दिखायी जाती है लेकिन ऐसा नहीं है।

यहां क्या गलत हो रहा है?

ui ग्रिड 3.0 नवीनतम रिलीज के HTML सेल टेम्पलेट Thats:

एचटीएमएल

<div ng-click="test()" ng-switch="row.entity[row.grid.columns.indexOf(col)].isPeriod"> 

    <div ng-switch-when="true"> 
     <tabset> 
      <tab> 
       <tab-heading> 
        <i class="glyphicon glyphicon-book"></i> 
       </tab-heading>period id: 
       {{ row.entity[row.grid.columns.indexOf(col)].id}} 
      </tab> 
      <tab select="alertMe()"> 
       <tab-heading> 
        <i class="glyphicon glyphicon-bell"></i> 
       </tab-heading> 
       {{row.entity[row.grid.columns.indexOf(col)].content}} 
      </tab> 

     </tabset>  <!-- PeriodTemplate --> 
    </div> 
    <div ng-switch-when="false"> 
     <div>Hello empty template</div> 
    </div>  <!-- EmptyPeriodTemplate --> 
</div> 

नियंत्रक:

'use strict'; 
angular.module('projectplanner').controller('DateplannerDayController', function ($scope, $state) { 


    var columnHeaderDates = ['col1','col2','col3','col4','col5','col6','col7'] 
    $scope.columns = createColumnHeaders(columnHeaderDates); 

var data = [{isPeriod: true, id: 10, rowNumber: 1},{isPeriod: false, id: 11, rowNumber: 2}] 

    $scope.test = function() 
    { 
    alert('test'); 
    }; 

    $scope.gridOptions = { 
     rowHeight: 200, 
     data: data, 
     enableSorting: false, 
     enableColumnMenu: false, 
     columnDefs: $scope.columns, 
     onRegisterApi: function (gridApi) { 
      $scope.gridApi = gridApi; 
      $scope.gridApi.core.addRowHeaderColumn(
       { name: 'rowHeaderCol', 
        displayName: '', 
        width: 100, 
        cellTemplate: '<div>row header template</div>' 
       }); 
     } 
    }; 

    function createColumnHeaders(columnHeaders) { 
     var columnDefinitions = []; 
     for (var i = 0; i < columnHeaders.length; i++) { 
      var column = { 
       name: columnHeaders[i], 
       cellTemplate: 'lessonplanner.day.celltemplate.html', 
       field: i + 'x' 
      } 
      columnDefinitions.push(column); 
     } 
     return columnDefinitions; 
    } 
}); 
+2

बाह्यस्कोप का उपयोग करें। मेरा उत्तर यहां देखें: http: //stackoverflow.com/questions/26621598/angular-ui-grid-events-in-cell-header-not-firing/26628361#26628361 – mainguy

+0

@mainguy बाहरी स्कॉप्स के साथ क्या करना है? कोई बाहरी दायरा नहीं है। यूई-ग्रिड से टट साइड पर एनजी-क्लिक नमूना एक ही चीज कर रहा है जैसे कि बाहरी स्कोप के बिना। एचएम ... यह अजीब बात है कि मैं कसम खाता हूं कि मैंने एक प्लंबर पर काम कर रहे सेल टेम्पलेट में यह एनजी-क्लिक देखा है, लेकिन यूई-ग्रिड कहता है: "यूआई-ग्रिड अलग-अलग दायरे का उपयोग करता है, इसलिए आपके एप्लिकेशन स्कोप चर के लिए कोई एक्सेस नहीं है पंक्ति या सेल टेम्पलेट। " ठीक है तो मुझे एक बाहरी दायरे की जरूरत है !!! धन्यवाद दोस्त! – Pascal

+0

इस समय यूई-ग्रिड के संस्करण, ट्यूटोरियल और मैनुअल एक खूनी गड़बड़ हैं। मुझे यह भी लगता है कि यह थोड़ी देर पहले बाहरी क्षेत्रों के बिना काम करता था। उम्मीद है कि यह जल्द ही बीटा से बाहर हो जाएगा। बीटीडब्ल्यू: प्रभावशाली प्लंकर आपने वहां बनाया है! – mainguy

उत्तर

13

इस पृष्ठ में पॉपिंग रखा मेरी खोजों और मैं टिप्पणियों में समाधान याद करने में कामयाब रहे। संक्षेप में, आपको बाहरीस्कोप का उपयोग करने की आवश्यकता है। Angular ui-grid events in cell header not firing और http://ui-grid.info/docs/#/tutorial/305_appScope

+1

बाहरी स्कॉप्स का अब उपयोग नहीं किया जाता है: http://stackoverflow.com/a/33792526/492130 –

+1

https://stackoverflow.com/ में स्वीकृत उत्तर प्रश्न/26621598/कोणीय-ui-grid-events-in-cell-header-not-firing/26628361 # 26628361 अब मान्य नहीं है, मार्कस का उत्तर देखें, यह ng-click = "grid.appScope.myfunction()" या ng है -click = "grid.appScope.myfunction (row.entity.cellfield)" – RandomUs1r

0

ऐसा इसलिए है क्योंकि यूई-ग्रिड का अपना नियंत्रक है और यह बाहरी नियंत्रक के बारे में नहीं जानता है।

सुविधा के लिए, निम्नलिखित करने के लिए .. 1. पहले नियंत्रक को यूई-ग्रिड को असाइन करें।

var vm = this; 
this.$scope.usersGridOptions = { 
appScopeProvider: vm, 
.... 
} 

अब, एक बार आप ग्रिड से नियंत्रक असाइन करते हैं, आप समारोह इस तरह, आह्वान कर सकते हैं ..

"<a type=\"button\" href=\"\" ng-click=\"function(row.entity)\"> {{ row.entity.text}} </a>" 
+0

यह मेरे लिए काम नहीं करता है – itachi

0

ui ग्रिड, सेल टेम्पलेट में क्योंकि सेल का अपना ही गुंजाइश है ,

1) do not use onclick='', instead should use ng-click='' 

2) ng-click='your_function()' will not work, should use, grid.appScope.your_function() 

3) when pass parameter in function(), do not use function({{xxx}}), see sample below 

cellTemplate: '<div class="ui-grid-cell-contents" title="TOOLTIP"><a href="" ng-click="grid.appScope.watering_modal(grid.appScope.editLink_tree_id(grid, row),grid.appScope.editLink_site_no(grid, row),grid.appScope.editLink_crm(grid, row), grid.appScope.editLink_package_no(grid, row))">{{grid.appScope.editLink_tree_id(grid, row)}}</a></div>' 
संबंधित मुद्दे