我想要做的東西很簡單:AngularJS指令 - 鏈接功能元素PARAM手錶功能不availble的
我定義的指令(「A」型)需要處理這個元素時,scope屬性改變。
JS
app.directive("autoAnimation", function()
{
return {
restrict: 'A',
scope: {
animateChanged: '=',
maxHeight: '@'//for the first time
},
link: function (scope, element, attrs)
{
var isFirstTime = true;
scope.$watch('animateChanged', function (newVal)
{
console.log(newVal)
//Trying to get the 'element' but it's not available - what can I do to get the ul element and manipulate it?
//why it's not available?
});
}
};
});
HTML
<body ng-controller="MainCtrl">
<input type="checkbox" ng-model='isChecked' />
<ul auto-animation animate-changed='isChecked'>
<li>Test</li>
<li>Test</li>
<li>Test</li>
<li>Test</li>
<li>Test</li>
</ul>
</body>
當 'animateChanged' 的問題是被改變時, '元素'(和範圍)參數不可用。
這裏是plunker。
我的問題:
1)它爲什麼不提供?
2)當'animateChanged'被改變時,我能做些什麼來操作'ul'元素(聲明指令的地方 - 請參閱HTML)?
編輯
我沒有檢查的例子,在這個例子中是可用的(我不好,對不起)。
但在我的項目中,它不可用,我不能把這個例子帶給我的情況......(在我的項目中,UL使用ng-repeat動態構建)。 任何想法可能會導致這種行爲?
看起來對我很好http://plnkr.co/edit/D2MfkqkMEUp5EgibIHDV?p=preview – 2014-11-14 12:59:32
你是對的!但它在我的項目中可用,我不知道爲什麼。 – cheziHoyzer 2014-11-14 13:11:01