Urigo / angular-meteor

Angular and Meteor - The perfect stack
https://www.angular-meteor.com/
MIT License
2.36k stars 621 forks source link

Proper way of using helpers? #1110

Closed derek-fong closed 8 years ago

derek-fong commented 8 years ago

I am trying to follow the helpers API example but when I try to do something like this in my controller

myModule.controller('MyCtrl', ['$scope', '$reactive', 'fruitFactory', function($scope, $reactive, fruitFactory) {
        $reactive(this).attach($scope);

        // Reactively get all `apples` from `fruitFactory`
        this.helpers({
            apples: () => fruitFactory.getAllApples()
         });
}]);

Client console keeps giving me this warnings:

defining 'apples' value helper, note that this feature will be deprecated in 1.4 in favor of using 'getReactively' - http://www.angular-meteor.com/api/1.3.1/get-reactively

overriding 'apples'

I have also tried using getReactively() but it does not seem to work properly so I am wondering what is the "proper" way of using helpers() / am I missing something when trying to use getReactively()?

0xfbravo commented 8 years ago

@DmitryEfimenko and @Urigo Here's my code for 'navigation' from the example above.

angular.module('gerenciadorImoveis').directive('navigation',
    () => {
        return {
            restrict: 'E',
            templateUrl: 'client/view/padrao/navigation.ng.html',
            controllerAs: 'navigation',
            controller: function($scope,$reactive){
                $reactive(this).attach($scope);
                this.sair = () => { Accounts.logout(); };

                this.autorun(() => {
                    this.logado = Meteor.userId() !== null;
                    this.usuario = Meteor.userId();
                });
            }
        }
    }
);

And at the body of my app:

<div class="ui fluid basic segment">
    <img draggable="false" src="pimentel.png" class="ui centered large image">
    <navigation></navigation>`
</div>
<div class="ui secondary fluid segment teal padded" ui-view></div>

It's all about angular-meteor. The 'ui-view' shows others directives with templates. Try something like this and you'll get this error too.

Error: scope.viewModel is not a function. (In 'scope.viewModel(this._vm)', 'scope.viewModel' is undefined)
Urigo commented 8 years ago

Everyone - 1.3.6 is out with all of the fixes you asked for.

@insidemybrain can you please provide a reproduction project with that scenario?

0xfbravo commented 8 years ago

@Urigo I've added you on my private project. Thanks.

nunof07 commented 8 years ago

I'm running version 1.3.6 and I have the same issue as @insidemybrain

Seems to only happen for directives placed directly in the body. Everything inside ui-view seems to work fine.

Also see #1238

dotansimha commented 8 years ago

@insidemybrain do you use angular or angular-with-blaze package? Also, where is your main HTML file located? in the root or inside client folder?

Urigo commented 8 years ago

closing this issue as the original problems were solved. Please open separate issues for separate problems. Thanks

Urigo commented 8 years ago

@insidemybrain can you tell me if now with 1.3.9_2 everything is working for you?

0xfbravo commented 8 years ago

@Urigo Everything is fine now! Thank you