jiangxujing11 发表于 2015-12-16 11:10:13

关于ng-repat,$location需要在特定的环境中才出效果吗

<!DOCTYPE HTML>
<html ng-app="myApp">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style>
#parent div{ width:300px; height:500px; border:1px #000 solid; margin:20px;}
#parent ul{ width:200px; position:fixed; top:0; right:0;}
</style>
<script src="angular.min.js"></script>
<script>
var m1 = angular.module('myApp',[]);
m1.controller('FirstControl',['$scope','$location','$anchorScroll',function($scope,$location,$anchorScroll){


    $scope.changeDiv=function(div){

      $location.hash(div);
    }

}]);
</script>
</head>
<body>
<div id="parent" ng-controller="FirstControl">
        <ul>
            <li ng-repeat="id in " ng-click="changeDiv('div'+id)">{{id}}aaaaaaaaaa</li>
    </ul>
    <div ng-repeat="id in " ng-attr-id="div{{id}}">{{id}}</div>
</div>
</body>
</html>
这是视频上老师的完整代码而他运行的结果是有五个div和五个li,但是我运行他的代码却只有一个div,一个li,是我需要安装什么环境吗?在本地跑不出来效果呢!求指教,感激不尽!

跨平台移动开发 发表于 2015-12-16 12:19:00

location 对应的js引入试试

jiangxujing11 发表于 2015-12-17 13:38:52

谢谢,有用!
页: [1]
查看完整版本: 关于ng-repat,$location需要在特定的环境中才出效果吗