angularjs - directive only works inside another directive -
i made directive filtering data. uses scope: true , no transclusion. somehow works inside ng-switch. maybe other directives havent tried.
my html looks this:
<my-filter source="{{foodarray}}" filter="reaction,category"> // source , filter properties on directive scope <div> <div class="span3"> <table class="table table-bordered"> <tr data-ng-repeat="item in filters.reaction"> // filters property of directive scope <td><input type="checkbox" data-ng-model="item.ischecked" data-ng-change="filterctrl.filterlist()"></td> <td>{{ item.value }}</td> </tr> </table> </div> </div> <table> <tbody> <tr data-ng-repeat="food in filtereddata"> // filtereddata object on directive scope // interating through filtereddata </tr> </tbody> </table> </my-filter>
here directive , controller:
angular.module('mymodule', []) .directive('myfilter', function() { return { restrict: 'e', scope: true, controller: ["$scope", function ($scope) { var filterctrl = this; $scope.filters = {}; filterctrl.inputarray = []; filterctrl.filterlist = function() { /* code tmp array created */ $scope.filtereddata = tmp; } }], controlleras: 'filterctrl', link: function(scope, element, attrs, filterctrl) { filterctrl.inputarray = angular.fromjson(attrs.source); scope.filtereddata = filterctrl.inputarray; // ... } } });
filtereddata , filters property of directives scope. when remove ng switch around data empty. scope.source property can array or object. when remove ng switch , give object source throws syntax error: syntaxerror: unexpected end of input @ object.parse (native) @ object.fromjson
which doesnt throw when use array.
not sure make of this. if had problem before love hear you.
Comments
Post a Comment