angularAMD icon indicating copy to clipboard operation
angularAMD copied to clipboard

Changes made to one controller be accessible through more than one route.

Open mateusmcg opened this issue 9 years ago • 8 comments

Also lets you load more than one script (directive, filter, controller, services, etc) per route, in case these are in separate files and/or folders.

mateusmcg avatar Jul 09 '15 11:07 mateusmcg

The build failed in these two lines of the utestProvider.js file: line 73: expect(elem.css("opacity")).toBe("0"); line 77: expect(elem.css("opacity")).toBe("1");

But i don't understand exactly why... If you could give me a light, i would appreciate.

Thanks.

mateusmcg avatar Jul 09 '15 12:07 mateusmcg

The error is due to animation. Could it be that bower.json somehow resolving to Angular 1.4.x? Per #138, angularAMD is having trouble with animation changes in Angular 1.4.x.

marcoslin avatar Jul 14 '15 20:07 marcoslin

bower.json is resolving "angular": "^1.3.0", Since this is a separate bug i just commented out these two lines of tests for the build to pass, so if you want you can uncomment them freely.

I don't know if you got a chance to see my changes but they let you load more than one file per page. What do i mean is, if you have a page with its controller, and this page has its own filter/directives/services in separate files, you can load them as well.

Look forward to hear from you. Thanks.

mateusmcg avatar Jul 20 '15 11:07 mateusmcg

I just checked your code and you basically changed load_controller into an array. I am not sure why you need this but let's defer that question for now.

With load_controller as array, you then use the same code:

require(load_controller, function (ctrl) {
    defer.resolve(ctrl);
    $rootScope.$apply();
});

As result, the code will only resolve the first controller in the array. Is that intentional? If it is, might be worth putting some comment as of why this is ok.

marcoslin avatar Jul 22 '15 09:07 marcoslin

Is the following question in SO the reason for this change?

http://stackoverflow.com/questions/31545274/angularamd-ui-router-multiple-views-does-not-load-controllers

marcoslin avatar Jul 23 '15 07:07 marcoslin

Actually no, this question in SO is not the reason for the change.

Yes, the code will resolve only the first controller in the array. I'll try to explain better.

Lets supose that we have a specific feature, for example:

  • registration-ctrl.js
  • registration.html

The code without my changes we evaluate that just fine. But what if the .js file for the controller is not the only file i want to load for this specific page? What if i want to load a filter or a service that are in separate files (registration-filters.js / registration-services.js) but i want to load them together with the controller?

That's why the array, to evaluate all the files that i need, and not only the controller.

Was i a little bit more clear now?

If you got any questions or didn't understand feel free to ask/comment :) Thanks!

mateusmcg avatar Jul 23 '15 11:07 mateusmcg

That is a lot clearer, thanks. I deal with the problem you described by setting the needed dependencies in the registration-ctrl.js file. Can you give me an usage example? We will need to add that README.md.

marcoslin avatar Jul 23 '15 14:07 marcoslin

In the project we have here we use it like this:

$routeProvider.when('/myModule/mySubmodule/myFeature2', angularAMD.route({ templateUrl: factory.getFileVersion('app/myModule/features/mySubmodule/myFeature2/myFeature2.html), controllerUrl: [factory.getFileVersion('app/myModule/features/mySubmodule/myFeature2/myFeature2-ctrl.js'), factory.getFileVersion('app/myModule/features/mySubmodule/myFeature2/myFeature2-filter.js'), factory.getFileVersion('app/myModule/features/mySubmodule/myFeature2/myFeature2-directive.js')] }));

In the controllerUrl we pass the array of files that we want to load for that specific page/controller.

And the getFileVersion function is to translate the url of the .js file (get the current path and name of the file) for production because they are renamed to a hash key to prevent cache.

If you got any questions feel free to ask.

mateusmcg avatar Jul 24 '15 19:07 mateusmcg