2

我有一個angularjs應用程序。該應用程序應該是Android和iOS的混合移動應用程序。我在項目中有一個JavaScript文件,它不是任何模塊的一部分。在該JavaScript文件中,我需要調用相應的模板URL,無論是通過$ state還是加載控制器的任何方法。

對於$範圍,我發現有很多方式在angularjs項目之外訪問它,但在$ state中找不到相同的方法。

+0

這個問題不是很清楚。爲什麼你需要在角度背景之外使用這些信息?那麼,非角度的代碼如何處理一個模板網址,該網址只是一個未被渲染的局部視圖? – Claies

回答

3

,我們可以使用Java腳本

window.location.href //to change location 

例如: 假設現在我在https://www.google.co.in/

現在我想轉到https://news.google.co.in/

,我們可以簡單的寫

window.location.href ="https://news.google.co.in/" 

它會n avigate該頁面

現在,在你的項目,你可能已經定義了路由這樣

function routeConfig($stateProvider, $urlRouterProvider, $httpProvider) { 
$stateProvider 
    .state('landing.home', { 
    url: '/home', 
    templateUrl: "app/components/homeFolder/home.html", 
    controller: 'homeController', 
    controllerAs: 'homec' 
    }) 
    .state('landing.hometwo', { 
    url: '/home1', 
    templateUrl: "app/components/OnHand/Templates/OnHandhome.html", 
    controller: 'OnHandController', 
    controllerAs: 'Onhand' 
    }) 

    }) 

現在,如果你是在angularjs控制器,你就乾脆用

$state.go('landing.home');// to navigate to your required location 

但是,如果你不在angularjs Module中你可以改變window.location來導航到所需的頁面

例如實現--- $ state.go('landing.home');你可以寫

window.location.href ="https:complete url" 

或以其他方式

window.location.hash ="#/home1" //the url which is defined for that state