Angular Js + UI路由器,每个拥有多个模块,每个拥有ui路由配置 - 怎么样?

时间:2015-09-17 17:29:16

标签: angularjs angular-ui-router angular-module

我的应用程序上有一个主应用程序,名为" bionico",此应用程序使用UI路由器 它拥有自己的$ stateProvider配置! 这没关系,它可以运作

但是我需要创建一个新模块(因为我试图在我的应用程序中插入一步一步的表单,你可以在这里找到代码:https://scotch.io/tutorials/angularjs-multi-step-form-using-ui-router

为了制作这个循序渐进的表格,我需要用它自己的$ stateProvider配置创建一个新模块,事情是它不起作用,我已经包含了这个名为&#的模块34; bionico.formApp"在我的主要应用程序中这样:

angular.module('bionico', ['ui.router', other modules, 'bionico.formApp'])

如果我尝试在内部使用控制器" bionico.formApp"它也会正常工作。这是该模块的代码:

// create our angular app and inject ngAnimate and ui-router 
//         =============================================================================
angular.module('bionico.formApp', ['ngAnimate', 'ui.router', ])

// configuring our routes 
// =============================================================================
.config(function($stateProvider, $urlRouterProvider) {

$stateProvider

    .state('form', {
        url: '/form',
        templateUrl: 'templates/campaignForm/form.html',
        controller: 'formCtrl'
    })

     // nested states 
    // each of these sections will have their own view
    // url will be nested (/form/profile)
    .state('form.profile', {
        url: '/profile',
        templateUrl: 'templates/campaignForm/form-profile.html'
    })

    // url will be /form/interests
    .state('form.interests', {
        url: '/interests',
        templateUrl: 'templates/campaignForm/form-interests.html'
    })

    // url will be /form/payment
    .state('form.payment', {
        url: '/payment',
        templateUrl: 'templates/campaignForm/form-payment.html'
    })


// catch all route
// send users to the form page 
$urlRouterProvider.otherwise('/form/profile');
})

// our controller for the form
// =============================================================================
.controller('formCtrl', function($scope) {

// we will store all of our form data in this object
$scope.formData = {};
 $scope.test = "FUNCIONA";
// function to process the form
$scope.processForm = function() {
    alert('awesome!');  
};

 });

但为了使这个表单有效,我需要使用<div ui-view></div>,当我把它放在我的文件上时没有任何反应,我认为这是因为该应用程序正在使用我的主模块&#34; bionico& #34; $ stateProvider配置而不是&#34; bionico.formApp&#34;

这是我的HTML代码:

        <div ng-controller="formCtrl">
                <!-- views will be injected here -->
             <div ui-view></div>

             {{test}}

来自formCtrl的{{test}}工作正常,它是在我的屏幕上打印变量,但就像我说的ui-view不是。有没有办法告诉角度我想要使用&#34; bionico.formApp&#34;配置而不是我主模块的配置? 你会如何解决这个问题?

就像我想我必须告诉棱角分明,从那一刻起我想要使用&#34; bionico.formApp&#34;但我不知道该怎么做。 我试过了 <div ng-app="bionico.formApp">但没有任何事情发生,甚至没有错误

然后我在堆栈上看到了我必须手动引导它,但后来我得到一个错误说&#34; bionico.formApp&#34;已经被引导

更新

人们建议我只需要在一个模块中解决问题,但我需要两个不同的默认路径,一个用于我的主应用程序,一个或我的表单,但这不会起作用。 我之所以尝试这项工作是因为我需要在我的应用程序上逐步形成(向导),如下所示:https://scotch.io/tutorials/angularjs-multi-step-form-using-ui-router

但我已经决定不值得麻烦了,我会尝试为角度js寻找另一个向导

我现在正在使用这个walktrough向导: https://github.com/mgonto/angular-wizard

我很容易安装,并且很容易自定义模板,我推荐!

0 个答案:

没有答案