2017-05-29 5 views
0

私はangularJSを学びたいと思っています。 配列の中にオブジェクトのセットがあります。これらのオブジェクトで動的コンテンツを作成しています。さて、それぞれのdivの「Add to 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

関連する問題