我尝试使用meanjs构建应用程序,因此大部分都使用了角度。这个想法是让用户能够为某个帖子添加标签和删除标签。在创建页面上添加和删除效果很好,但是一旦我尝试在编辑帖子页面上添加或删除它就不再有用了。
下面是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>
以下是控制器
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');
}
};
当我输入标签并点击x时,我可以看到日志,但页面上没有任何实际情况发生,但如果我只创建帖子,一切正常。
请帮助我谢谢