我疯了。我正在尝试在我的角应用程序中实现指令,但我甚至无法获得一个简单的模板来显示。如果有人能帮我发现问题,我会很感激! (我对角度很新,所以如果有人能解决任何关于结构的错误或提示......我很高兴得到指针)
对于大量的代码感到抱歉。
继承了我的HTML的基本部分:
<!DOCTYPE html>
<html ng-app='app'>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="stylesheets/stylesheet.css">
<link href="libs/angular-xeditable-0.1.8/css/xeditable.css" rel="stylesheet">
<title>Kaching</title>
</head>
<body>
<div id='wrapper' class='container' ng-controller='itemController'>
<h1>Kaching</h1>
<kcItemTable>
</kcItemTable>
<tabset>
<tab heading='Oannonserad'>
<div id='unannounced'>
<table class='table table-hover'>
<thead>
<tr>
<th>Name</th>
<th>Description</th>
<th>Cost</th>
<th>Starting Price</th>
<th>Ending Price</h>
<th>Buyer</th>
<th>Comment</th>
<th>Status</th>
<th>
<button class='btn btn-default' ng-click='openModal()'>
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
</button>
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat='item in unannouncedItemList'>
<td>
<a href="#" editable-text="item.name" onaftersave="updateItem(item._id, item)">{{ item.name || "empty" }}</a>
</td>
<td>
<a href="#" editable-text="item.description" onaftersave="updateItem(item._id, item)">{{ item.description || "empty" }}</a>
</td>
<td>
<a href="#" editable-text="item.cost" onaftersave="updateItem(item._id, item)">{{ item.cost || "empty" }}</a>
</td>
<td>
<a href="#" editable-text="item.startprice" onaftersave="updateItem(item._id, item)">{{ item.startprice || "empty" }}</a>
</td>
<td>
<a href="#" editable-text="item.endprice" onaftersave="updateItem(item._id, item)">{{ item.endprice || "empty" }}</a>
</td>
<td>
<a href="#" editable-text="item.buyer" onaftersave="updateItem(item._id, item)">{{ item.buyer || "empty" }}</a>
</td>
<td>
<a href="#" editable-text="item.comment" onaftersave="updateItem(item._id, item)">{{ item.comment || "empty" }}</a>
</td>
<td>
<a href="#" editable-select="item.status" e-ng-options="s.value as s.text for s in statuses" onaftersave="updateItem(item._id, item)">{{ showStatus(item) }}</a>
</td>
<td>
<button class='btn btn-danger' ng-click='removeItem(item._id)'>
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</td>
</tr>
</tbody>
</table>
</div>
</tab>
<tab heading='Annonserad'>
<div id='announced'>
<table class='table table-hover'>
<thead>
<tr>
<th>Name</th>
<th>Description</th>
<th>Cost</th>
<th>Starting Price</th>
<th>Ending Price</h>
<th>Buyer</th>
<th>Comment</th>
<th>Status</th>
<th>
<button class='btn btn-default' ng-click='openModal()'>
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
</button>
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat='item in announcedItemList'>
<td>
<a href="#" editable-text="item.name" onaftersave="updateItem(item._id, item)">{{ item.name || "empty" }}</a>
</td>
<td>
<a href="#" editable-text="item.description" onaftersave="updateItem(item._id, item)">{{ item.description || "empty" }}</a>
</td>
<td>
<a href="#" editable-text="item.cost" onaftersave="updateItem(item._id, item)">{{ item.cost || "empty" }}</a>
</td>
<td>
<a href="#" editable-text="item.startprice" onaftersave="updateItem(item._id, item)">{{ item.startprice || "empty" }}</a>
</td>
<td>
<a href="#" editable-text="item.endprice" onaftersave="updateItem(item._id, item)">{{ item.endprice || "empty" }}</a>
</td>
<td>
<a href="#" editable-text="item.buyer" onaftersave="updateItem(item._id, item)">{{ item.buyer || "empty" }}</a>
</td>
<td>
<a href="#" editable-text="item.comment" onaftersave="updateItem(item._id, item)">{{ item.comment || "empty" }}</a>
</td>
<td>
<a href="#" editable-select="item.status" e-ng-options="s.value as s.text for s in statuses" onaftersave="updateItem(item._id, item)">{{ showStatus(item) }}</a>
</td>
<td>
<button class='btn btn-danger' ng-click='removeItem(item._id)'>
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</td>
</tr>
</tbody>
</table>
</div>
</tab>
<tab heading='Såld'>
<div id='sold'>
<table class='table table-hover'>
<thead>
<tr>
<th>Name</th>
<th>Description</th>
<th>Cost</th>
<th>Starting Price</th>
<th>Ending Price</h>
<th>Buyer</th>
<th>Comment</th>
<th>Status</th>
<th>
<button class='btn btn-default' ng-click='openModal()'>
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
</button>
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat='item in soldItemList'>
<td>
<a href="#" editable-text="item.name" onaftersave="updateItem(item._id, item)">{{ item.name || "empty" }}</a>
</td>
<td>
<a href="#" editable-text="item.description" onaftersave="updateItem(item._id, item)">{{ item.description || "empty" }}</a>
</td>
<td>
<a href="#" editable-text="item.cost" onaftersave="updateItem(item._id, item)">{{ item.cost || "empty" }}</a>
</td>
<td>
<a href="#" editable-text="item.startprice" onaftersave="updateItem(item._id, item)">{{ item.startprice || "empty" }}</a>
</td>
<td>
<a href="#" editable-text="item.endprice" onaftersave="updateItem(item._id, item)">{{ item.endprice || "empty" }}</a>
</td>
<td>
<a href="#" editable-text="item.buyer" onaftersave="updateItem(item._id, item)">{{ item.buyer || "empty" }}</a>
</td>
<td>
<a href="#" editable-text="item.comment" onaftersave="updateItem(item._id, item)">{{ item.comment || "empty" }}</a>
</td>
<td>
<a href="#" editable-select="item.status" e-ng-options="s.value as s.text for s in statuses" onaftersave="updateItem(item._id, item)">{{ showStatus(item) }}</a>
</td>
<td>
<button class='btn btn-danger' ng-click='removeItem(item._id)'>
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</td>
</tr>
</tbody>
</table>
</div>
</tab>
<tab heading='Skickad'>
<div id='shipped'>
<table class='table table-hover'>
<thead>
<tr>
<th>Name</th>
<th>Description</th>
<th>Cost</th>
<th>Starting Price</th>
<th>Ending Price</h>
<th>Buyer</th>
<th>Comment</th>
<th>Status</th>
<th>
<button class='btn btn-default' ng-click='openModal()'>
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
</button>
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat='item in shippedItemList'>
<td>
<a href="#" editable-text="item.name" onaftersave="updateItem(item._id, item)">{{ item.name || "empty" }}</a>
</td>
<td>
<a href="#" editable-text="item.description" onaftersave="updateItem(item._id, item)">{{ item.description || "empty" }}</a>
</td>
<td>
<a href="#" editable-text="item.cost" onaftersave="updateItem(item._id, item)">{{ item.cost || "empty" }}</a>
</td>
<td>
<a href="#" editable-text="item.startprice" onaftersave="updateItem(item._id, item)">{{ item.startprice || "empty" }}</a>
</td>
<td>
<a href="#" editable-text="item.endprice" onaftersave="updateItem(item._id, item)">{{ item.endprice || "empty" }}</a>
</td>
<td>
<a href="#" editable-text="item.buyer" onaftersave="updateItem(item._id, item)">{{ item.buyer || "empty" }}</a>
</td>
<td>
<a href="#" editable-text="item.comment" onaftersave="updateItem(item._id, item)">{{ item.comment || "empty" }}</a>
</td>
<td>
<a href="#" editable-select="item.status" e-ng-options="s.value as s.text for s in statuses" onaftersave="updateItem(item._id, item)">{{ showStatus(item) }}</a>
</td>
<td>
<button class='btn btn-danger' ng-click='removeItem(item._id)'>
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
</td>
</tr>
</tbody>
</table>
</div>
</tab>
</tabset>
<div id='createNewItemModal'>
<script type='text/ng-template' id='modalContent.html'>
<div class='modal-header'>
<h3 class='modal-title'>Create new item</h3>
</div>
<div class='modal-body'>
<div class='form-group'>
<label for="nameInput">Name</label>
<input type="input" class="form-control" id="nameInput" placeholder="Name" ng-model='item.name'>
</div>
<div class='form-group'>
<label for="descInput">Description</label>
<input type="input" class="form-control" id="descInput" placeholder="Description" ng-model='item.description'>
</div>
<div class='form-group'>
<label for="costInput">Cost</label>
<input type="input" class="form-control" id="costInput" placeholder="Cost" ng-model='item.cost'>
</div>
<div class='form-group'>
<label for="startPriceInput">Starting Price</label>
<input type="input" class="form-control" id="startPriceInput" placeholder="Starting Price" ng-model='item.startprice'>
</div>
<div class='form-group'>
<label for="endPriceInput">Ending Price</label>
<input type="input" class="form-control" id="endPriceInput" placeholder="Ending Price" ng-model='item.endprice'>
</div>
<div class='form-group'>
<label for="commentInput">Comment</label>
<input type="input" class="form-control" id="commentInput" placeholder="Comment" ng-model='item.comment'>
</div>
</div>
<div class='modal-footer'>
<button class='btn btn-warning' ng-click="cancelModal()">Cancel</button>
<button class='btn btn-success' ng-click="addItem()">Create</button>
</div>
</script>
</div>
</div>
<!-- Library Scripts -->
<script src="libs/angular.min.js"></script>
<script src="libs/angular-xeditable-0.1.8/js/xeditable.min.js"></script>
<script src="libs/ui-bootstrap-tpls-0.13.0.min.js"></script>
<!-- Application Scripts -->
<script src='scripts/app.js'></script>
<script src='scripts/controllers/itemController.js'></script>
</body>
</html>
继承了我的完整控制人员:
var app = angular.module('app', ['xeditable', 'ui.bootstrap'])
app.run(function(editableOptions) {
console.log('running xeditable')
editableOptions.theme = 'bs3'
});
function logSuccess(data, status, headers, config) {
console.log(status)
console.log(headers())
console.log(config)
console.log(data)
}
function logError(data, status, headers, config) {
console.log(status)
console.log(headers())
console.log(config)
console.log(data)
}
app.controller('itemController', ['$scope', '$http', '$modal', '$filter', function($scope, $http, $modal, $filter) {
var refresh = function() {
console.log('Getting items')
$http.get('/items').success(function(data, status, headers, config) {
logSuccess(data, status, headers, config)
$scope.unannouncedItemList = data.unannounced
$scope.announcedItemList = data.announced
$scope.soldItemList = data.sold
$scope.shippedItemList = data.shipped
}).error(function(data, status, headers, config) {
logError(data, status, headers, config)
})
}
$scope.$on("refresh", function (event, args) {
refresh()
});
refresh()
$scope.statuses = [
{value: 'UNANNOUNCED', text: 'Oannonserad'},
{value: 'ANNOUNCED', text: 'Annonserad'},
{value: 'SOLD', text: 'Såld'},
{value: 'SHIPPED', text: 'Skickad'}
];
$scope.showStatus = function(item) {
var selected
$scope.statuses.forEach(function(entry) {
if (entry.value == item.status) {
selected = entry
}
})
return (item.status && selected) ? selected.text : 'Not set';
};
$scope.openModal = function() {
var modalInstance = $modal.open({
animation: true,
templateUrl: 'modalContent.html',
controller: 'modalInstanceController',
size: null,
scope: $scope
});
}
$scope.removeItem = function(id) {
console.log(id)
$http.delete('/items/' + id).success(function(data, status, headers, config) {
logSuccess(data, status, headers, config)
refresh()
}).error(function(data, status, headers, config) {
logError(data, status, headers, config)
})
}
$scope.updateItem = function(id, item) {
console.log("Update item with id: " + id)
console.log("Item to update: " + item)
$http.put('/items/' + id, item).success(function(data, status, headers, config) {
logSuccess(data, status, headers, config)
refresh()
}).error(function(data, status, headers, config) {
logError(data, status, headers, config)
})
}
}])
app.controller('modalInstanceController', ['$scope', '$http','$modalInstance', function ($scope, $http, $modalInstance) {
$scope.addItem = function() {
console.log('Post item')
var item = $scope.item
item.status = 'UNANNOUNCED'
$http.post('/items' , item).success(function(data, status, headers, config) {
logSuccess(data, status, headers, config)
$modalInstance.dismiss('cancel')
$scope.$emit('refresh');
}).error(function(data, status, headers, config) {
logError(data, status, headers, config)
})
}
$scope.cancelModal = function () {
$modalInstance.dismiss('cancel')
}
}])
app.directive('kcItemTable', function() {
return {
restrict: 'E',
template: 'habba habba'
}
})
答案 0 :(得分:3)
在您看来,替换&#34; kcItemTable&#34;的所有实例by&#34; kc-item-table&#34;。
答案 1 :(得分:2)
您必须在模板中调用您的指令:
<kc-item-table></kc-item-table>