as an experiment I tried creating a controller in AngularJS using Kotlin.
- here is the example html (which other than including the generated kotlin JS files looks like any simple angularjs template).
- the main entry point defines the controller
- there's a simple kotlin API for angularjs
At least it works even though it doesn't do very much :)
I guess its no surprise that the kotlin code is a little clunky, due to the $scope
escaping due to $ being not allowed on identifiers and having to use the [“functionName”] subscript operators to define functions on the scope object but at least it shows it can be done. Here’s how the code would look in javascript (would look a bit neater still in typescript with the () => syntax for function declarations)
var myApp = angular.module("myApp", []); myApp.controller("ProductController", function($scope) { $scope.clear = function() { console.log("Cleared!"); }; $scope.save = function() { console.log("Saved!"); }; });