2016-05-24 3 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> 

マイbaseCtrlng-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

あなたは答えを書いて、私はあなたがビューを命名している場合は、 'templateUrl'が却下されていることをかなり確信して – pietro909

答えて

0

このブロックは正しくなことがありますあなたは、名前のアイテムが状態設定オブジェクトのキーであることを確認してください

'' : { 
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

:-)それを受け入れる必要があります。 – tommyd456

関連する問題