angelozerr / angularjs-eclipse

AngularJS Eclipse Plugin
https://angularjs.org/
Eclipse Public License 1.0
328 stars 90 forks source link

Automatic link between HTML template & controller #102

Open angelozerr opened 10 years ago

angelozerr commented 10 years ago

See https://thinkster.io/egghead/templateurl/ for a sample with templateUrl.

When templateUrl is used, today link between HTML file and JS controller is done at hand https://github.com/angelozerr/angularjs-eclipse/wiki/Angular-Explorer-View#user-content-html-template-linkunlink

It should be cool if tern plugin angular.js could retrieve the link between HTML template and controller : link will be done automaticly without doing at hand.

sebastienblanc commented 10 years ago

That would be really nice but also quite complex to implement because there are different situation :

  1. The easy one, the template has a "ng-controller" attribute in its root tag, we can just parse that to make the link
  2. $routeProvider is used to link templates and controllers , like :
 $routeProvider.when('/contacts', {
                templateUrl : 'partials/contact/search.html',
                controller : SearchContactController

Here we need to parse the $routeProvider

  1. $stateProvider is used, like :
.state('tab.dash', {
      url: '/dash',
      views: {
        'tab-dash': {
          templateUrl: 'templates/tab-dash.html',
          controller: 'DashCtrl'
        }
      }
    })

There are probably other ways to bind controllers to template which I'm not aware of.

angelozerr commented 10 years ago

I know it's not an easy task (taht's why I had implemented link 'at hand').

But I would like to really improve (at first) templateUrl with this issue but with the following issue https://github.com/angelozerr/angularjs-eclipse/issues/103 (completion for templateUrl).

But to do that I need that tern support object litteral with clean mean (pay the author of tern.js to support that?)

angelozerr commented 9 years ago

@sebastienblanc I will start this feature but I will manage for the moment 2 cases :

app.directive("zippy", function(){
 return {
   restrict: "E",
   transclude: true,
   scope: {
     title: "@"
   },
   templateUrl: "zippy.html",
   link: function(scope){
     scope.isContentVisible = false;
     scope.toggleContent = function(){
       scope.isContentVisible = !scope.isContentVisible;
     };
   };
 };
});
$routeProvider.when('/contacts', {
  templateUrl : 'partials/contact/search.html',
  controller : SearchContactController

$stateProvider is not a part of angular, but an extension (so I will not manage it for the moment). I have created an issue for that https://github.com/angelozerr/angularjs-eclipse/issues/137