2016-05-24 48 views
0

我点名的观点:UI路由器命名视图和NG-控制器

.state('home', { 
    url: '/', 
    views: { 
    '' : { 
     templateUrl: '/layouts/main.html', 
     controller: ['$rootScope', function($rootScope) { 
     $rootScope.css.background = "#ebeced"; 
     }] 
    }, 
    '[email protected]': { templateUrl: '/templates/nav.html' }, 
    '[email protected]': { templateUrl: '/home/menu.html'}, 
    '[email protected]': { templateUrl: '/templates/feed.html' }, 
    '[email protected]': { templateUrl: '/home/footer.html' } 
    } 
}) 

main.html看起来是这样的(注意,NG-控制器):

<div ng-controller="baseCtrl"> 
    <div ui-view="nav"></div> 

    <div class="wrapper"> 

    <div id="menu"> 
     <div ui-view="menu"></div> 
    </div> 

    <div ui-view="main"></div> 

    <div id="footer"> 
     <div ui-view="footer"></div> 
    </div> 

    </div> 
</div> 

baseCtrl是不承认ng-model值在ui-view中的任何一个文本框中。

<input type="text" ng-model="url" ng-blur="addUrl()" /> 

baseCtrl

$scope.url = ""; //required or get error about not being defined 
$scope.addUrl = function() { 
    console.log($scope.url); //nothing??? 
} 

上午我做一个愚蠢的错误地方?

UPDATE: 我想我已经解决了这个问题 - 我需要定义baseCtrl作为控制器每个视图了。

+0

你应该写答案,并接受它:-) – pietro909

回答

0

此块可能是uncorrect:

'' : { 
templateUrl: '/layouts/main.html', 
//..etc 

你肯定不愿透露姓名的项目应在状态配置对象的关键?您可以尝试把它differenlty:

.state('home', { 
    url: '/', 
    templateUrl: '/layouts/main.html', 
    controller: ['$rootScope', function($rootScope) { 
     $rootScope.css.background = "#ebeced"; 
    }], 
    views: { 
    '[email protected]': { templateUrl: '/templates/nav.html' }, 
    '[email protected]': { templateUrl: '/home/menu.html'}, 
    '[email protected]': { templateUrl: '/templates/feed.html' }, 
    '[email protected]': { templateUrl: '/home/footer.html' } 
    } 
}) 
+0

我敢肯定,如果有一个名为观点,'templateUrl'被否决。 – tommyd456