锚标签的ui-sref无法点击

时间:2019-04-28 13:42:45

标签: angularjs

当我为锚标记设置ui-sref时无法单击,但是当我将其替换为href属性时它将很好地工作

            <table>
               <tr>
                <td class="sideMenu">
                    <a ui-sref="#/Home">Home</a>
                    <a ui-sref="#/Course">Course</a>
                    <a ui-sref="#/Student">Student</a>
                </td>
                <td class="mainMenu">
                    <ui-view></ui-view>
                </td>
            </tr>
                        </table>
    </div>
</body>
</html>

当我为锚标记设置ui-sref时无法单击,但是当我将其替换为href属性时它将很好地工作   这是我的angularjs代码

/// <reference path="angular-1.7.8/angular.js" />
/// <reference path="angular-1.7.8/angular-route.js" />

var myApp = angular
    .module('myModule', ['ui.router'])
    .config(function ($stateProvider,$urlRouteProvider) {
        $stateProvider
            .state('Home', {
                url: '/Home',
                templateUrl: 'Template43/Home.html',
                controller: 'homeController',
                controllerAs: 'homeCtr'
            })
            .state('Course', {
                url: '/Course',
                templateUrl: 'Template43/Course.html',
                controller: 'courseController',
                controllerAs: 'courseCtr'
            })
            .state('Student', {
                url: '/Student',
                templateUrl: 'Template43/Student.html',
                controller: 'studentController',
                controllerAs: 'studentCtr',
                resolve: {
                    studentList: function ($http) {
                        return $http.get('WebService43RouteUi.asmx/getData')
                            .then(function (response) {
                                return response.data;
                            });
                    }
                }
            });
        $locationProvider.hashPrefix('');
    })

2 个答案:

答案 0 :(得分:0)

angular-ui-router.js需要ui-router,而不是angular-route.js

在HTML中,将#/Home替换为Home

在Javascript中,将url: '/Home'替换为url: '#/Home'

答案 1 :(得分:-1)

此代码正常工作。

HTML:

 <tr>
    <td class="sideMenu">
        <a ui-sref="Home">Home</a>
        <a ui-sref="Course">Course</a>
        <a ui-sref="Student">Student</a>
    </td>
    <td class="mainMenu">
        <ui-view></ui-view>
    </td>
</tr>

script.js:

/// <reference path="angular-1.7.8/angular.js" />

var myApp = angular
    .module('myModule', ['ui.router'])
    .config(function ($stateProvider) {
        $stateProvider
            .state('Home', {
                url: '#/Home',
                templateUrl: 'Template43/Home.html',
                controller: 'homeController',
                controllerAs: 'homeCtr'
            })
            .state('Course', {
                url: '#/Course',
                templateUrl: 'Template43/Course.html',
                controller: 'courseController',
                controllerAs: 'courseCtr'
            })
            .state('Student', {
                url: '#/Student',
                templateUrl: 'Template43/Student.html',
                controller: 'studentController',
                controllerAs: 'studentCtr',
                resolve: {
                    studentList: function ($http) {
                        return $http.get('WebService43RouteUi.asmx/getData')
                            .then(function (response) {
                                return response.data;
                            });
                    }
                }
            });
    })