This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 246444 - Controller not recognized if declared in IIFE
Summary: Controller not recognized if declared in IIFE
Status: VERIFIED FIXED
Alias: None
Product: web
Classification: Unclassified
Component: AngularJS (show other bugs)
Version: 8.1
Hardware: PC Linux
: P3 normal (vote)
Assignee: Roman Svitanic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-08-13 16:00 UTC by Vladimir Riha
Modified: 2015-03-06 08:40 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
sample project (2.85 MB, application/zip)
2014-08-13 16:00 UTC, Vladimir Riha
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Vladimir Riha 2014-08-13 16:00:08 UTC
Created attachment 148687 [details]
sample project

Please check the attached project, controllers are defined like this:


(function () {

    function PhoneListCtrl($scope, Phone) {
        $scope.phones = Phone.query();
        $scope.orderProp = 'age';
    }

    function  PhoneDetailCtrl($scope, $routeParams, Phone) {
        $scope.phone = Phone.get({phoneId: $routeParams.phoneId}, function (phone) {
            $scope.mainImageUrl = phone.images[0];
        });
        $scope.neco =1;

        $scope.setImage = function (imageUrl) {
            $scope.mainImageUrl = imageUrl;
        }
    }
    var phonecatControllers = angular.module('phonecatControllers', []);
    phonecatControllers.controller('PhoneListCtrl', ['$scope', 'Phone', PhoneListCtrl]);
    phonecatControllers.controller('PhoneDetailCtrl', ['$scope', '$routeParams', 'Phone', PhoneDetailCtrl]);


})();


And with this pattern, code completion/go to declaration does not work in partials. This pattern comes from [1]

Thank you

[1] http://toddmotto.com/opinionated-angular-js-styleguide-for-teams/
Comment 1 Roman Svitanic 2015-03-04 16:56:31 UTC
CC should work now in partials if controllers are declared in IIFE and "controller as" pattern is used:

(function () {

    function PhoneListCtrl(Phone) {
        this.phones = Phone.query();
        this.orderProp = 'age';
    }

    function  PhoneDetailCtrl($routeParams, Phone) {
        this.phone = Phone.get({phoneId: $routeParams.phoneId}, function (phone) {
            this.mainImageUrl = phone.images[0];
        });
        this.neco = 1;

        this.setImage = function (imageUrl) {
            this.mainImageUrl = imageUrl;
        };
    }
    var phonecatControllers = angular.module('phonecatControllers', []);
    phonecatControllers.controller('PhoneListCtrl', ['Phone', PhoneListCtrl]);
    phonecatControllers.controller('PhoneDetailCtrl', ['$routeParams', 'Phone', PhoneDetailCtrl]);

})();

Other approaches should work as soon as the following two issue will be fixed: bug #250898 and bug #250899.

http://hg.netbeans.org/web-main/rev/af1aa6fcfb41
Comment 2 Quality Engineering 2015-03-05 04:09:01 UTC
Integrated into 'main-silver', will be available in build *201503050001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/af1aa6fcfb41
User: Roman Svitanic <rsvitanic@netbeans.org>
Log: #250892 and #246444: Better CC in AngularJS partials
Task #250892 - No CC when controller registered using reference
Comment 3 Vladimir Riha 2015-03-06 08:40:06 UTC
Thank you, verified


Product Version: NetBeans IDE Dev (Build 201503060001)
Java: 1.8.0_40; Java HotSpot(TM) Client VM 25.40-b25
Runtime: Java(TM) SE Runtime Environment 1.8.0_40-b25
System: Linux version 3.13.0-35-generic running on i386; UTF-8; en_US (nb)