Angularjs 如何根据用户操作更改指令数据
我接到指令了Angularjs 如何根据用户操作更改指令数据,angularjs,angularjs-directive,Angularjs,Angularjs Directive,我接到指令了 angular.module('test', []) .run(function($http, $templateCache) { $http.get('http://localhost/testtem/test.html', { cache: $templateCache }); }) .directive('ngTest', ['$parse', '$http', '$compile', '$templateCache','$locatio
angular.module('test', [])
.run(function($http, $templateCache) {
$http.get('http://localhost/testtem/test.html', {
cache: $templateCache
});
})
.directive('ngTest', ['$parse', '$http', '$compile', '$templateCache','$location',
function ($parse, $http, $compile, $templateCache,$location)
{
var linker = function (scope, element, attrs,ngModel)
{
element.bind('click', function () {
var ddd = scope.selectedvalue;
scope.testDataList = Enumerable.From(scope.testDataList)
.Where(function (x) {
return x.LeafParentId == '1' //leafParentId
}).ToArray()
});
};
return {
templateUrl : 'http://localhost/testtem/test.html',
transclude: true,
restrict: "E",
scope: false,
link: linker
};
}]);
这是模板:
<section ng-controller="testCtrl">
<section class="box1">
<input type="button" name="" id="1"
ng-value="checkData(DataList[0].Name)"
/>
</section>
<section class="box1">
<input type="button" name="" id="2"
ng-value="checkData(DataList[1].Name)"
/>
</section>
<section class="box1">
<input type="button" name="" id="3"
ng-value="checkData(DataList[2].Name)"
/>
</section>
这是html:
<section data-ng-app="templateApp">
<div data-ng-controller="testCtrl">
<ng-test ></ng-test>
</div>
</section>
需要明确的是,除了dom渲染之外,所有功能都可以完美工作。
我想根据用户操作显示值
当我再次初始化指令的element.bind函数中的testDatalist时
我试着使用编译和监视,但什么都没有发生
谢谢,
Ishay指令名称与标记不匹配。另外,最好不要对自定义指令使用ng前缀。。。意味着它是角度的一部分。创建复制问题的演示谢谢,我编辑了名称,只是作为示例,名称是正确的,我想知道如何根据用户操作再次呈现dom。我知道我需要使用watch/compile,但是在哪里?哦。。更改范围时在内部单击事件…angular不知道。最好使用ng click而不是绑定自己的click处理程序。。。或使用范围。$apply
<section data-ng-app="templateApp">
<div data-ng-controller="testCtrl">
<ng-test ></ng-test>
</div>
</section>