相关疑难解决方法(0)

AngularJS - UI-router - 如何配置动态视图

我很难找到任何关于通过数据库动态使用ui-router的文档.对于课程而言,一切都是硬编码的.

我的Json:

[
   {
       "name": "root",
       "url": "/",
       "parent": "",
       "abstract": true,
       "views": [
            {"name": "header", "templateUrl": "/app/views/header.html"},            
            {"name" :"footer", "templateUrl": "/app/views/footer.html" }
       ]
   },
    {
        "name": "home",
        "url": "",
        "abstract" : false,
        "parent": "root",
        "views": [
            {"name": "container@", "templateUrl": "/app/views/content1.html"},            
            {"name" :"left@", "templateUrl": "/app/views/left1.html" }
       ]
    },
    {
        "name": "about",
        "url": "/about",
        "abstract": false,
        "parent": "root",
        "views": [
             {"name": "container@", "templateUrl": "/app/views/content2.html"},            
             {"name" :"left@", "templateUrl": "/app/views/left2.html" }
            ]
    }
]
Run Code Online (Sandbox Code Playgroud)

我的应用:

'use strict';

var $stateProviderRef = null;
var $urlRouterProviderRef …
Run Code Online (Sandbox Code Playgroud)

angularjs angular-ui-router

30
推荐指数
2
解决办法
4万
查看次数

带有requirejs的angular-ui-router,延迟加载控制器

你能帮我理解如何在视图之前的下面的例子中加载控制器吗?看起来在尚未加载控制器的情况下立即加载视图.

//app.js
$stateProvider.state('index', {
    url: "/",
    views: {
        "topMenu": {
            templateUrl: "/Home/TopMenu",
            controller: function($scope, $injector) {
                require(['controllers/top-menu-controller'], function(module) {
                    $injector.invoke(module, this, { '$scope': $scope });
                });
            }
        }
    }
});

//top-menu-controller.js
define(['app'], function (app) {
    app.controller('TopMenuCtrl', ['$scope', function ($scope) {
        $scope.message = "It works";
    }]);
});

//Home/TopMenu
<h3>TopMenu</h3>
<div ng-controller="TopMenuCtrl">
    {{message}}
</div>
Run Code Online (Sandbox Code Playgroud)

requirejs angularjs angular-ui-router

13
推荐指数
2
解决办法
1万
查看次数

标签 统计

angular-ui-router ×2

angularjs ×2

requirejs ×1