【发布时间】:2016-07-02 19:21:20
【问题描述】:
我尝试了各种方式(将范围保持为假等,但无法在控制器中更改我的范围),我是否遗漏了什么。
指令:
angular.module("ui.materialize.inputfield", [])
.directive('inputField', ["$timeout", function ($timeout) {
return {
transclude: true,
scope: {},
link: function (scope, element) {
$timeout(function () {
Materialize.updateTextFields();
// The "> > [selector]", is to restrict to only those tags that are direct children of the directive element. Otherwise we might hit to many elements with the selectors.
// Triggering autoresize of the textareas.
element.find("> > .materialize-textarea").each(function () {
var that = $(this);
that.addClass("materialize-textarea");
that.trigger("autoresize");
var model = that.attr("ng-model");
if (model) {
scope.$parent.$watch(model, function (a, b) {
if (a !== b) {
$timeout(function () {
that.trigger("autoresize");
});
}
});
}
});
// Adding char-counters.
element.find('> > .materialize-textarea, > > input').each(function (index, countable) {
countable = angular.element(countable);
if (!countable.siblings('span[class="character-counter"]').length) {
countable.characterCounter();
}
});
});
},
template: '<div ng-transclude class="input-field"></div>'
};
}]);
这是我的看法
<div ng-controller="Example Controller"
<div input-field class="col l3">
<input type="text" ng-model="class1" length="150">
<label>Class</label>
{{class1}}
</div>
{{class1}}
</div>
我看到只有指令范围的 class1 发生了变化,但最后一个 class1 没有发生变化,
如果我用 $scope.class1 = 9 初始化我的控制器 只有第一个 class1 正在改变,但没有第二个 class1。任何人都可以帮助我解决这个问题
【问题讨论】:
标签: angularjs angularjs-directive angularjs-scope angular-ui-bootstrap materialize