Announcement

Collapse
No announcement yet.

Angular and custom libraries

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    Angular and custom libraries

    What is the latest version of Angular is supported? What if I have d.ts files and want to build a C# library out of it, how ca I do it?

    Thank you,
    Alex

    #2
    Hi alex4998,

    Take a look at Building a Definition Library guide for creating own libraries.

    The latest version supported by Retyped is AngularJS 1.6.
    Below is a simple example from the official tutorial written in C#

    index.html
    <!DOCTYPE html>
    
    <html ng-app="phonecatApp">
    <head>
        <meta charset="utf-8" />
        <title>angular_demo</title>
    
        <script src="bin/Debug/bridge/bridge.js"></script>
        <script src="bin/Debug/bridge/bridge.console.js"></script>
        <script src="bin/Debug/bridge/angular_demo.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.10/angular.js"></script>
    
    </head>
    <body ng-controller="PhoneListController">
        <ul>
            <li ng-repeat="phone in phones">
                <span>{{phone.name}}</span>
                <p>{{phone.snippet}}</p>
            </li>
        </ul>
    </body>
    </html>
    App.cs
    using Bridge;
    using System;
    using Retyped;
    using static Retyped.angular;
    
    namespace angular_demo
    {
        public class App
        {
            public static void Main()
            {
                // Define the `phonecatApp` module
                var phonecatApp = angular3.module("phonecatApp", new string [0]);
    
                // Define the `PhoneListController` controller on the `phonecatApp` module
                phonecatApp.controller("PhoneListController", ControllerCtor<Scope>(scope => {
    
                    scope.phones = new[]
                    {
                        new Phone
                        {
                            name = "Nexus S",
                            snippet = "Fast just got faster with Nexus S."
                        },
                        new Phone
                        {
                            name = "Motorola XOOMâ„¢ with Wi-Fi",
                            snippet = "The Next, Next Generation tablet."
                        },
                        new Phone
                        {
                            name = "MOTOROLA XOOMâ„¢",
                            snippet = "The Next, Next Generation tablet."
                        }
                    };
                }));
            }
    
            [Template("function ($scope) { ({ctor})($scope); }")]
            public static extern angular2.Injectable<angular2.IControllerConstructor> ControllerCtor<T>(Action<T> ctor);
    
            [ObjectLiteral]
            class Scope
            {
                public Phone[] phones;
            }
    
            [ObjectLiteral]
            class Phone
            {
                public string name;
                public string snippet;
            }
        }
    }
    In order to refer angular.js global variables, we need to disable modules auto loading in bridge.json file.

    If you want to load angular.js as a module, you don't need this setting, but in this case you'll need to serve the script from the project dir.

    bridge.json
      "loader": {
        "manualLoading": "true",
        "skipManualVariables": "true"
      },
    Hope that helps.

    Comment


      #3
      Thank you.
      That sheds a light on a few things. Now, I wonder why there is no support for Angular 4 or 6. Out team will be reluctant in adopting Bridge.Net technology if there is no support for more recent Angular version even though the whole Bridge.Net idea and implementation is great.
      I was under the impression that Retyped project would allow to generate custom Bridge.Net C# libraries out of type script declarations. Am I wrong and this is not possible?

      Comment


        #4
        I believe the main issue Retyped had with parsing the Angular TypeScript files is that their .ts files contain all manner of edge cases that are different than what the vast majority of TypeScript lib authors are using. Circular dependencies in their references, etc. We just could not devote the time required to unpack all the issues with Angular, so had to leave it for now. There wasn't much demand for Angular either, so that contributed to our decision to devote our resources to other cleanly structured libs.

        As well, we don't have the resources available to figure this out now either, so Retyped will not be able to support any version of Angular other than what is currently supported.

        Hope this helps answer your questions.

        Comment


          #5
          All right, I got it about the Angular. Is there a way to easily build C# libraries out of our custom d.ts files? How to do it if it's possible?

          Comment


            #6
            We had hoped to offer Retyped as an option for local custom conversion of d.ts files into .cs files, but the pulse we received from the community is that there wasn't a lot of interest in the idea, so we had to put the project on hold. I'm still hoping we can get can back to this at some point, but for now, the team is focused on other work.

            Comment

            Working...
            X