$ scope не работает в файле app.js.Но $ scope работает, когда в файле HTML есть содержимое файла app.js. - PullRequest
0 голосов
/ 29 мая 2019

Когда я сам использую 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>

1 Ответ

1 голос
/ 09 июля 2019

myOrderBy - это имя переменной в файле app.js, и вы используете myOrder в файле HTML. Просто измените кого-либо относительно другого. Просто орфографическая ошибка.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...