0
我想从url中的一个页面传递数据并从url中获取新的页面,例如我想在url中添加10,20。像在给定的实施例I在通过sumurl 10,20它示出了其在DIV NG-视图总和,但我想显示它在sumurl.html或input.html我怎样才能去angularjs的另一个页面
var app=angular.module('myapp',['ngRoute']);
app.config(['$routeProvider',function($routeProvider){
$routeProvider
.when('/sumurl/:a/:b',{
templateUrl:'sumurl.html',
controller:'sumurl'
})
.when('/input',{
templateUrl:'input.html',
controller:'input'
})
.when('/',{
template:'Welcome to my app'
}).otherwise({
template:'Not Available'
})
}]);
app.controller('sumurl',['$scope','$routeParams',function($scope,$routeParams){
$scope.n1=$routeParams.a;
$scope.n2=$routeParams.b;
}]);
app.controller('input',['$scope','$location','$interpolate',function($scope,$location,$interpolate){
$scope.n1=0;
$scope.n2=0;
$scope.dosum=function(){
var url=$interpolate('/sumurl/{{n1}}/{{n2}}')($scope);
//console.log(url);
$location.path(url);
}
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.5/angular.min.js"></script>
<div ng-app="myapp">
<ul>
<li><a href="#/sumurl/10/20">some url</a></li>
<li><a href="#/input">input</a></li>
<li></li>
</ul>
<div ng-view>
</div>
</div>
Sumurl是输入是两个HTML文件
sumurl.html
<div>
a = {{n1}}<br>
b = {{n2}}<br>
Sum = {{(n1-0)+(n2-0)}}
</div>
而且input.html
<div>
n1 = <input type="number" ng-model="n1"/>
n2 = <input type="number" ng-model="n2"/>
<button ng-click="dosum()">Sum</button>
</div>
你可以给我的例子吗? –