$ location.path没有绑定角度js中的数据

时间:2014-12-22 11:26:15

标签: javascript jquery html angularjs

我有两个角度js控制器。单击recorddetails.html中的ng-href链接时, 我能够看到结果绑定为“活动名称是练习”,但如果我通过在send.html中单击带有find()的按钮进行ng-click,则相同。我能够看到recorddetails.html,但是页面显示时没有将数据绑定为“活动名称为{{activity}}”。我已经提供了下面的代码供参考。接下来,提供一些有价值的解决方案。

index.html

            <div ng-controller="controllerOne">
            <a ng-href="#/recorddetails/100">Running</a> 
          </div> 

recorddetails.html

        <div ng-controller="controllerTwo">
            <p> The activity name is {{activity}}</a>// The scope name is Exercise 
          </div>

send.html

         <div ng-controller="controllerThree">
           <button ng-click="find()">
          </div>

JS档案

          angular.module('exampleapp', ['ngRoute').config(
                [ '$provide', '$httpProvider', '$routeProvider', function($provide,               $httpProvider, $routeProvider) {
                    $routeProvider. 

                      when('/recorddetails/:id', {
                            templateUrl: '/records/recorddetails.html',
                            controller: 'controllerTwo'
                           .otherwise({
                        redirectTo: '/defaultpage'
                      });




            app.controller('controllerOne',
                [ '$scope','$location',function($scope,$location) {`enter code here`
                        }

            app.controller('controllerTwo',
                [ '$scope','$location',function($scope,$location) {
        $scope.activity = "Exercise";
                        }

   app.controller('controllerThree',
                [ '$scope','$location',function($scope,$location) {
$scope.find = function(){
        $location.path("/recorddetails/100");
                        }
}

1 个答案:

答案 0 :(得分:0)

&#13;
&#13;
var app=angular.module('binding',['ngRoute'])
app.config(['$routeProvider',function ($routeProvider)
{
    $routeProvider
        .when('/',
        {
            templateUrl:'one.html',
            controller:'controllerOne'
        })
        .when('/recorddetails/:id', {
            templateUrl: 'recorddetails.html',
            controller: 'controllerTwo'

        })
        .when('/send', {
            templateUrl: 'send.html',
            controller: 'controllerThree'

        })
}])






app.controller('controllerOne',function($scope,$location){

})

app.controller('controllerTwo', function($scope,$location) {
          
        $scope.activity = "Exercise";
                        })


   app.controller('controllerThree',function($scope,$location) {
$scope.find = function(){
    console.log('in 3');
        $location.path("/recorddetails/100");
                        }
})
&#13;
<html ng-app="binding">

<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.5/angular-route.min.js"></script>
<script src="routefile.js"></script>
</head>

<body>

<div ng-view>

</div>

</body>
</html>
&#13;
&#13;
&#13;