0

I have simple directive:

var goodsProperties = angular.module('goodsProperties', []);

goodsProperties.directive('showGoodsProperties', function() {    
    var directive = {
        priority: 0,
        template: '<h1>Hello World</h1>',
        replace: false,
        transclude: false,
        restrict: 'C'
    };

    return directive;
});

And html for it's:

<div ng-app="goodsProperties">
    <div class="showGoodsProperties"></div>
</div>

And i want add element dynamic on Javascript. Full code see at http://jsfiddle.net/ZvPmh/5/

I have function addClick(), what add new tag with directive class.

If i call addClick() in body, all work fine. But if i call addClick() on a-tag, angular don't see new element like directive.

3
  • If i call addClick() in body, all work fine. But if i call addClick() on a-tag Can you explain? Commented Oct 8, 2013 at 9:31
  • If i add <div class="showGoodsProperties"> in <script> angular see it's. But if i have <a onclick="addClick"></a>, and this tag add <div>, angular don't see it's. Commented Oct 8, 2013 at 9:43
  • nm, see Cherniv solution, use controller Commented Oct 8, 2013 at 9:45

1 Answer 1

3

Stay in "Angular world". Use Controllers to control your stuff. Define a controller like this:

var Ctrl = function($scope){
    $scope.divs = [{}];
    $scope.add = function(){
        this.divs.push({});
    }
}

And use it with your markup like this:

<div ng-app="goodsProperties" ng-controller="Ctrl">
    <a href="#" ng-click="add()">add</a>
    <div ng-repeat="div in divs" class="showGoodsProperties"></div>
</div>

Working example: http://jsfiddle.net/ZvPmh/7/

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, but i can't use it, all HTML generated by ExtJS. And if i add ng-controller i have same problem, angular don't know about new controller.
@Hello may be you could change some ExtJS settings?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.