我有一个指令
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>
这是app + ctrl:
angular.module('templateApp', ['test'])
.controller('testCtrl', function ($scope, $http, $sce) {
$scope.testDataList = "";
$http.post("http://localhost/Service.svc/GetDataMysql", { leafParentId: 0 })
.then(
function (data) {
if (data.data) {
$scope.testData = Enumerable.From(data)
.Select(function (x) { return x })
.ToArray();
$scope.testDataList = $scope.testData[0].Value;
}
});
这是html:
<section data-ng-app="templateApp">
<div data-ng-controller="testCtrl">
<ng-test ></ng-test>
</div>
</section>
只是为了清楚所有功能完美除了dom渲染。 我想根据用户操作显示值 当我再次在element.bind函数中启动testDatalist(在指令上)
我尝试使用编译和监视,没有任何事情发生,
谢谢, Ishay