将范围更改从Angular 1.1隔离到1.2

时间:2015-05-10 20:23:08

标签: javascript angularjs

Angular N00b在这里,我有一些有隔离范围指令。我创建了一个JS Fiddle来显示问题,但奇怪的是它似乎在Angular v1.1中按预期工作,但是在1.2+中它没有用。

基本上,我试图创建隔离范围指令,每个指令在指令的内容本身都有html。您将在ng-show属性中看到我尝试在具有隔离范围的指令上调用isActive方法,但是对于角度1.2 +

,该方法永远不会被触发

我确定我的隔离范围配置不正确,仍然试图绕过它。

谢谢!



var app = angular.module('myApp', []);

app.directive('stage', function () {
    return {
        restrict: 'A',
        controller: ['$scope', '$sectionService', function ($scope, $sectionService) {

            // doesn't do much yet

        }],
    };
});

app.directive('section', function () {
    return {
        restrict: 'A',
        scope: {
            sectionIndex: '=section'
        },
        controller: ['$scope', '$sectionService', function ($scope, $sectionService) {

            $scope.isActive = function () {
                console.log("is active", $sectionService.activeSection, $scope.sectionIndex);
                return $sectionService.activeSection == $scope.sectionIndex;
            };

        }],
    };
});

app.factory('$sectionService', function () {
    return {
        activeSection: 0
    };
});

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.min.js"></script>
<body ng-app="myApp">
<div stage>
    <div section='0' ng-show='isActive()'>This is my first section</div>
    <div section='1' ng-show='isActive()'>This is my second section</div>
</div>
</body>
&#13;
&#13;
&#13;

更新:对不起伙计们,我包括错误的小提琴。那应该有用。

0 个答案:

没有答案