2015-10-21 120 views
0

在這裏,我想通過$ scope.myData的 app.js在指令mcsaForm和使用myTemplate.html對象的屬性。我的代碼正常工作,除了我上面提到的方法。

app.js

myApp.controller("myCont", function($scope){ 
    . 
    some code 
    . 
    . 
    $scope.getTypeOfEvent = function(typeOfEvent, idOfEvent) 
    { 
     if(typeOfEvent == "MCQ") 
     { 

     if(idOfEvent) 
     { 
      var indexOfEvent =$scope.namesTwo.Events.indexOf("idOfEvent")+1; 
      var valueAtIndex = $scope.namesTwo.Events[indexOfEvent].id; 
      $scope.myData = $scope.namesTwo[valueAtIndex]; 
      console.log($scope.myData); // output: Object {eventId: "001", TimeOfEvent: "2", EventType: "MCQ"} 
     } 
     //fetchJsonDir.gettingContData; 
     $scope.mCSSQ(typeOfEvent,idOfEvent); 
     } 
    } 
}); 

myDirective.js

videoCourseApp.directive("mcsaForm",['fetchJsonDir', function(fetchJsonDir){ 
return{ 
    restrict: "C", 
    templateUrl: "assets/template_blocks/Preview_forms/myTemplate.html", 
    scope: { 
     myData: "=" 
    }, 
    compile: function(scope, element, attrs) 
    { 
     $("#mcss_option_list").append("Hello"); 
    }, 
    controller: function($scope){  
     $scope.onSubmitHidePanel = function() 
     { 
      $(".mcsa_form").fadeOut("slow", function(){ 
        $(this).remove(); 
      });- 
     } 
    } 
} 
}]); 

myTemplate.html

<div id=mcss_option_list> 

</div> 
<div> 
    001, 2, MCQ//print myData.eventId, myData.TimeOfEvent or whatever.. 
</div> 

回答

0

使用您的指令就像

<div class="mcsa-form" my-data="myData"></div> 

你會得到你的指令的myTemplate.html

<div id=mcss_option_list> 
    {{myData.TimeOfEvent}} 
</div>