awinogradov / bem-ng

Library for work with AngularJS in bem-projects
15 stars 3 forks source link

support bem-components #7

Open Guria opened 9 years ago

Guria commented 9 years ago

Define directive in template for each block from bem-components. In directives:

Maybe it should be implemented in separate repo.

awinogradov commented 9 years ago

@Guria i think about this. Thanks!

Guria commented 9 years ago

working example for input:

modules.define('angular-bem', ['jquery'], function(provide, $, ngBem) {
    provide(ngBem.directive('inputAngular', function() {
        return {
            restrict : 'C',
            require : '?ngModel',
            link : function(scope, element, attrs, ngModel) {
                if(!ngModel) return;

                var input = $(element).bem('input');

                ngModel.$render = function() {
                    input.setVal(ngModel.$viewValue || '');
                };

                input.on('change', function() {
                    scope.$evalAsync(read);
                });

                read();

                function read() {
                    ngModel.$setViewValue(input.getVal());
                }
            }
        }
    }));
});
awinogradov commented 9 years ago

Cool!!!

Guria commented 9 years ago

We can list here bem-components blocks that need such directives.