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