angularjs ui-rouetr控制器未注册时出错

时间:2018-01-26 15:58:59

标签: angularjs angular-ui-router

我正在使用ui-router进行路由,但我得到一个错误,因为控制器不是注册

<title></title>
 <script src="../../Scripts/angular.js"></script>
    <script src="../../Scripts/angular-ui-router.js"></script>
    <script src="Admin_MyApp.js"></script>
    <script src="../EmployeePages/EmployeeScripting/Employee_MyApp.js">
<ul>
  <li><a ui-sref="Contact()">Contact</a></li>
                </ul>

admin_Myapp.js

var app = angular.module('Admin_MyApp', ['ui.router']);
    app.config(function ($stateProvider, $urlRouterProvider) {
        $stateProvider      
            .state('Contact', {
            url: 'contact',
            templateUrl: '/Kpmg/AdminPages/EmployeeDetails/Feedback.html',
            controller: 'abc'
        })
    })

contact.js

app.controller('abc', function ($scope) {

1 个答案:

答案 0 :(得分:0)

代码中有两个问题:

1-您需要将contact.js添加到html

2-您的控制器必须在您的州之前定义。所以这是正确的顺序:

// define your module first
var app = angular.module('Admin_MyApp', ['ui.router']);

// define your controller on the module
app.controller('abc', function ($scope) {
   // your controller
});

// define the state
app.config(function ($stateProvider, $urlRouterProvider) {
    $stateProvider      
        .state('Contact', {
        url: 'contact',
        templateUrl: '/Kpmg/AdminPages/EmployeeDetails/Feedback.html',
        controller: 'abc'
    })
})