angularjs - Adding Tags work on create page, but wont work on edit page angular -
i'm trying build app meanjs of uses angular. idea user able add tags , delete tags post. add , deleting works great on create page once try add or delete on edit post page doesn't work anymore.
below html
<section data-ng-controller="productscontroller" data-ng-init="findone()"> <div class="page-header"> <h1>edit product</h1> </div> <div class="col-md-12"> <form class="form-horizontal" data-ng-submit="update()" novalidate> <fieldset> <div class="form-group"> <div class="controls"> <label class="control-label" for="name">name</label> <input type="text" data-ng-model="product.name" id="name" class="form-control" placeholder="name" required> <div class="tag-input-ctn"> <div data-ng-repeat="(key, tag) in product.tags" class="input-tag"> {{ tag.name }} <div class="delete-tag" data-ng-click="deletetag(key)">×</div> </div> <input type="text" data-tag-input="" data-ng-model="newtag" data-ng-style="{width: inputwidth}" data-new-tag="addtag()" data-delete-tag="deletetag()"> </div> </div> </div> <div class="form-group"> <div ng-click="update()" value="update" class="btn btn-default">update</div> </div> <div data-ng-show="error" class="text-danger"> <strong data-ng-bind="error"></strong> </div> </fieldset> </form> </div>
below controller
angular.module('products').controller('productscontroller', ['$scope', '$stateparams', '$location', 'authentication', 'products', function($scope, $stateparams, $location, authentication, products) { $scope.authentication = authentication; $scope.tags = []; $scope.addtag = function() { if ($scope.newtag.length === 0) { return; } $scope.tags.push({name: $scope.newtag}); console.log('addtag ran'); $scope.newtag = ''; }; $scope.deletetag = function(key) { if ($scope.tags.length > 0 && $scope.newtag.length === 0 && key === undefined) { $scope.tags.pop(); } else if (key !== undefined) { $scope.tags.splice(key, 1); console.log('tagspops'); } };
i can see logs when enter tags , click on x's, nothing happens on page, yet works fine if i'm creating post.
please me thanksss
Comments
Post a Comment