Когда я сам использую Angular Script на странице HTML, все работает нормально, включая $ scope.myOrderBy. Но когда я использую тот же скрипт в файле Static / JS / app.js, все работает, кроме $ scope.myOrderBy.
Я хочу использовать переменную $ scope.myOrderBy в app.js.
Я обнаружил, что код действительно хорошо работает в самом HTML, но не все работает в файле app.js.
// app.js file
var app = angular.module("productManager", []);
app.controller("productController", function ($scope, $http) {
$scope.products = [];
// This doesn't work and refelct back to html page.
$scope.myOrderBy = "news";
$scope.confirmDelete = false;
$scope.productForm = {
id: -1,
proName: "",
brand: "",
madeIn: "",
price: ""
};
_refreshProductData();
function _refreshProductData() {
}
// Submit Button Button
$scope.submitProduct = function () {
};
// Create New Product Button
$scope.createNewProduct = function () {
};
// Delete Product Button
$scope.deleteProduct = function (product) {
};
// Edit Product Button
$scope.editProduct = function (product) {
};
// Success Function
function _success(response) {
};
// Error Function
function _error(response) {
};
// Clear Form Data
function _clearFormData() {
});
Обновление 1: Добавлен файл HTML:
<body ng-app = "productManager" ng-controller = "productController">
<div align = "center">
{{myOrder}}
<h4>Product Manager : </h4>
<form ng-submit = "submitProduct()">
.
.
.
</form>
<button ng-click = "createNewProduct()">Create New Product</button>
</div>
<div align = "center">
<h1>Product Catalogue : </h1>
<br/>
<input type="text" placeholder = "Enter Any" />
<table>
<thead>
<tr>
.
.
</tr>
<tr>
.
.
.
<th>Action</th>
</tr>
</thead>
<tbody>
<tr ng-repeat = "product in products | orderBy : myOrder>
.
.
.
<td>
<button ng-click = "editProduct(product)">Edit</button>
<button ng-click = "deleteProduct(product)">Delete</button>
</td>
</tr>
</tbody>
</table>
</div>
</body>