angular js 中的按钮不起作用

Button in angular js was not functioning

提问人:Alfi husni 提问时间:11/12/2023 更新时间:11/12/2023 访问量:20

问:

我试图在我的angular js程序中制作一个按钮,但是将从索引页移动到主页的按钮从未起作用。

我现在有 3 个文件,它们是

索引.html, (/Applications/MAMP/htdocs/EIN_IA/index.html)

首页.js, (/Applications/MAMP/htdocs/EIN_IA/scripts/app/home/home/home.js)

首页.html, (/Applications/MAMP/htdocs/EIN_IA/scripts/app/home/home/home.html)

和 main.js (/Applications/MAMP/htdocs/EIN_IA/scripts/app/home/main.js)

该按钮位于索引.html中,我希望将其重定向到home.html

这是我尝试过的代码

索引.html

    <body ng-controller="AppCtrl">

        <div class="index_landing">
            <div class="col-md-14">

                <h3>Selamat datang di Service Centre</h3>
                <h2>Welcome to Service Centre </h2>

                <button class="Nw_cus" ng-click='NwCustBtn()'>Pelanggan Baru<br>New Customer</button>
                <button class="Ol_cus" style="margin-left: 40px;" ng-click='OldCustBtn()'>Pelanggan Lama<br>Old Customer</button>
                <br>
                <br>
                <button class="Pbtn" ng-click='PickupCustB()'>Pengambilan Printer<br>Pick-up</button>

            </div>

        </div>
        <script type="text/javascript" src="scripts/app/home/home/home.js"></script>
</body>

首页.js

// home.js

angular.module('app', [])

.config(['$routeProvider', function ($routeProvider) {
    $routeProvider
    .when('/home', {
        templateUrl: 'scripts/app/home/home/home.html', 
        controller: 'HomeCtrl'
    })
    
    
}])

.controller('AppCtrl', function ($scope, $location) {
    console.log('AppCtrl controller initialized');
    $scope.landing = function () {
        console.log('Landing function called');
        $location.url('/home');
    };

    $scope.NwCustBtn = function () {
        console.log('NwCustBtn clicked');
        $scope.landing();
    };

    $scope.OldCustBtn = function () {
        console.log('OldCustBtn clicked');
        $scope.landing();
    };

    $scope.PickupCustB = function () {
        console.log('PickupCustB clicked');
        $scope.landing();
    };
});

main.js

angular.module('app').config(function ($routeProvider, RestangularProvider) {
    RestangularProvider.setBaseUrl("");

    RestangularProvider.setRequestInterceptor(
        function (elem, operation, what) {
            if (operation === 'put') {
                elem.id = undefined;
                return elem;
            }
            return elem;
        });
})

.config(['$routeProvider', function ($routeProvider) {
    $routeProvider
        .when('/home', {
            templateUrl: 'scripts/app/home/home/home.html',
            controller: 'AppCtrl'
        })
        // ... other routes
}])
.controller('AppCtrl', function ($scope, $location) {
    // Your controller code here
});

我也尝试添加控制台,但控制台日志中没有出现任何内容。

JavaScript HTML AngularJS

评论


答: 暂无答案