2017-05-29 93 views
0

我正在嘗試學習angularJS。 我有一組數據中的對象。我用這些對象創建動態內容。現在,當我點擊每個div的「Add to outlook」按鈕時,我需要將它們添加到我的Outlook中。使用'addtocalendar'在angularJS中添加事件

如何在此處使用'addtocalendar'這個?

下面的代碼,我到目前爲止已經寫 -

angular.module('myApp', []).controller('myCtrl', function($scope){ 
 
    $scope.card = [{ 
 
    Name: "New Year Celebration", 
 
    Description: "", 
 
    Venue: "", 
 
    StartDate: "Fri Dec 29 2017 23:30:00 GMT+0530", 
 
    EndDate: "Sat Dec 30 2017 00:30:00 GMT+0530", 
 
    EventID: "1" 
 
}, { 
 
    Name: "25th Anniversary Celebration", 
 
    Description: "25th Anniversary Celebration of organization", 
 
    Venue: "Auditorium", 
 
    StartDate: "Wed May 31 2017 17:30:00 GMT+0530", 
 
    EndDate: "Wed May 31 2017 20:30:00 GMT+0530", 
 
    EventID: "2" 
 
}, { 
 
    Name: "Annual Day", 
 
    Description: "", 
 
    Venue: "", 
 
    StartDate: "Fri Oct 13 2017 14:30:00 GMT+0530", 
 
    EndDate: "Fri Oct 13 2017 17:30:00 GMT+0530", 
 
    EventID: "3" 
 
}]; 
 

 

 

 
    $scope.add = function(eventObj) { 
 
    $scope.eventID= this.eventObj.EventID; 
 
    $scope.startDate= this.eventObj.StartDate; 
 
    $scope.endDate= this.eventObj.EndDate; 
 
    $scope.venue= this.eventObj.Venue; 
 
    $scope.subject= this.eventObj.Name; 
 
    $scope.result= this.eventObj.Description; 
 
    //console.log(this); 
 
    $scope.icsMSG = "BEGIN:VCALENDAR\nVERSION:2.0\nBEGIN:VEVENT\nUID:[email protected]\nDTSTAMP:"+ $scope.startDate +"\nATTENDEE;CN=My Self ;RSVP=TRUE:MAILTO:[email protected]\nORGANIZER;CN=Me:MAILTO:[email protected]\nDTSTART:" + $scope.startDate +"\nDTEND:" + $scope.endDate +"\nLOCATION:" + $scope.venue + "\nSUMMARY:"+ $scope.subject + "\nEND:VEVENT\nEND:VCALENDAR"; 
 
    window.open("data:text/calendar;charset=utf8," + escape($scope.icsMSG)); 
 
    }; 
 
});
.event { 
 
    height: 150px; 
 
    width: 250px; 
 
    border: 1px solid lightgrey; 
 
    background-color: skyblue; 
 
    margin: 10px; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> 
 
<div ng-app="myApp" ng-controller="myCtrl"> 
 
    <div ng-repeat="eventObj in card" class="event"> 
 
    Subject: <span>{{eventObj.Name}}</span> 
 
    <br /><br /> \t 
 
    Venue:<span>{{eventObj.Venue}}</span> 
 
    <br /><br /> \t 
 
    Date:<span>{{eventObj.StartDate | date:'fullDate'}}</span> 
 
    <br /><br /> 
 
    <button ng-click="add(eventObj.EventID)">Add to Outlook</button> 
 
    </div> 
 
</div>

+0

你可以嘗試這個[鏈接](https://github.com/jshor/angular-addtocalendar) –

+0

我已經鏈接上面的URL。但我不知道如何使用它!你能告訴我如何使用我的代碼以上? – Sunny

回答

1

首先,你必須在HTML您angularjs和addtocalendar腳本。之後,在你的app.js文件中,你需要像下面那樣指定依賴關係。你的情況是「角ATC」

angular.module('myApp', ['angular-atc']).controller('myCtrl', function($scope) { 
     ... 
     // All your code here 
     ... 
    } 

而在你的HTML

<body ng-app="myApp"> 
    <div ng-controller="myCtrl"> 
     <div ng-repeat="eventObj in card"> 
      <addtocalendar 
       start-date="{{eventObj.StartDate}}" 
       end-date="{{eventObj.EndDate}}" 
       title="{{eventObj.Name}}" 
       location="{{eventObj.Venue}}" 
       class-name="btn btn-sm btn-default dropdown-toggle" 
       description="{{eventObj.Description}}"> 
      </addtocalendar> 
     </div> 
    </div> 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> 
    <script src="./path/to/your/addtocalender.js"></script> 
    <script src="./path/to/your/controller.js"></script> 
</body> 

您可以參閱site過,當我再深究角addtocalendar它與最新突破版本,我的工作代碼我已經使用v1.3.0

+0

我的舊html如何?我的意思是我如何從我的數組對象中獲取數據? – Sunny

+0

我編輯了答案,現在檢查你是否能趕上 – Kanagu