2017-01-08 31 views
0

我有在印度的財產信息的DIV,如果用戶點擊一個按鈕,秀格angularjs

的頁面應該另一頁上重定向和我的整個DIV應該是複製

而另一頁上打開

<div class="box2"> 
        <div style=""> 
         <img src="2.jpg" style="border: 2px solid #EEEEEE; height: 180px;" class="col-lg-6 col-md-6 col-sm-12 col-xs-12" /> 
        </div> 
        <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12 select"> 
         <div class="borderdiv"> 
          <span ng-repeat="i in data2" style="font-size:16px; font-weight:bold">{{i.A}}</span> 
         </div> 
         <div class="borderdiv"> 
          <span ng-repeat="i in data2" style="font-size:12px; font-weight:lighter">Available For <b>{{i.B}}</b> </span> 
         </div> 
         <div class="borderdiv"> 
          <span ng-repeat="i in data2" style="font-size:14px; font-weight:normal">Area <b>{{i.C}}</b> Security <b> Rs. {{i.F}}</b></span> 
         </div> 
         <div class="borderdiv"> 
          <span ng-repeat="i in data2" style="font-size:14px; font-weight:normal">Rental Unit In<b style="cursor:pointer"> {{i.D}}</b></span> 
         </div> 
         <br /> 
         <div class="borderdiv"> 
          <span ng-repeat="i in data" style="font-size:14px; font-weight:normal"> 
           Features 
           <br /> 
           <span class="glyphicon glyphicon-eject" style="margin-left:20px;"></span> 
           <span class="glyphicon glyphicon-chevron-left" style="margin-left:20px;"></span> 
           <span class="glyphicon glyphicon-chevron-right" style="margin-left:20px;"></span> 
          </span> 
         </div> 
         <br /> 
         <div class="borderdiv"> 
          <span ng-repeat="i in data2" style="font-size:14px; font-weight:normal">{{i.E}}</span> 
         </div> 
        </div> 
       </div> 

這是我的div

<button ng-click="click()">click to view data</button> 

這是我的按鈕

如果我想在其他頁面上看到相同的數據,我需要做什麼?

+0

的第二頁是在同一個項目或不同的項目/網站? –

+0

同一項目\ ... –

+0

您可以在其他頁面上擁有相同的HTML代碼(DIV),並在按鈕上單擊,您可以將對象保存在$ rootScope中,並在下一頁的$ rootScop中再次讀取該對象。 –

回答

0

您需要創建一個服務器端結構模板,它將生成div。例如,在PHP

function getViewData() { 
    ?> 
    <button ng-click="click()">click to view data</button> 
    >?php 
} 

而且你可以在你的結構,如果你使用的是PHP文件中像這樣加:

<?php getViewData(); ?> 
0

我會建議你去同一個角度工廠其中包含您正在查找的數據,並在相應頁面中使用html模板。

按鈕代碼保持相同

<button ng-click="click()">click to view data</button> 

創建一個新的角度廠如下

angular.module('myApp').factory('appVariables',function(){ 
     var data2=[]; 
     return{ 
       data2,data2 
     } 
}); 

你的控制器應包含以下點擊()方法

angular.module('myApp').controller('appController',function($scope,appVariables){ 

     $scope.click=function(){ 
      appVariables.data2=$scope.data2; 
     } 
}) 

轉到另一個頁面注入appVariables作爲控制器的依賴關係,您可以在應用中獲得相同的data2。

此代碼是genric,因爲您提供的信息非常少。

0

我已經爲你組合了一個樣本。我無法創建多個HTML頁面。所以你必須把它們放在不同的文件中。

var app = angular.module('sample', []);] 
 
//JS1 
 
app.controller('page1Controller', ['$scope','$http','$rootScope', function($scope, $http){ 
 
    
 
    $scope.page1 = {}; 
 
    $scope.page1.title = "Page1"; 
 
    
 
    $scope.click = function(page){ 
 
    $rootScope.page = page; 
 
    } 
 
    
 
}]); 
 

 

 
//JS2 
 
app.controller('page2Controller', ['$scope','$http','$rootScope', function($scope, $http){ 
 
    
 
    $scope.init = function(){ 
 
    alert("alrt") 
 
    $scope.page2 = $rootScope.page; 
 
    } 
 
    
 
    
 
}]);
<div ng-app="sample"> 
 
    
 
    <!--Page1--> 
 
    <div ng-controller="page1Controller"> 
 
    
 
    <div>{{page1.title}}</div> 
 
    <button ng-click="click(page1)">click to view data</button> 
 
</div> 
 
    
 
    <!--Page2--> 
 
    <div ng-app="sample"> 
 
    <div ng-controller="page2Controller" ng-init="init()"> 
 
    
 
    <div>{{page2.title}}</div> 
 
    
 
</div>