【发布时间】:2016-04-10 04:29:47
【问题描述】:
这里我创建了自定义指令,用于显示和隐藏 json 数据中的特定字段,这里我的问题是角度版本,在低版本中它可以工作 (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js),但高版本它不支持 (https://code.angularjs.org/1.3.15/angular.js)
请查看以下链接 http://plnkr.co/edit/h3MrWQjopbqzYa0Y5pOT?p=preview
var app = angular.module('testApp', []);
app.directive('telBasictext1', ['$http', 'telngshowservice', function($http, telngshowservice) {
return {
restrict: 'AEC',
require: 'ngModel',
scope: {
ngModel: '=',
placeHold: '@',
checkId: '@',
className: '@',
ngmaxLength: '@',
ngminLength: '@',
lblvalue: '@',
textboxSize: '@',
lblSize: '@',
validate: '@',
ngShow: '@',
textboxtype: '@',
getString: '@',
position: '@',
labelPosition: '@',
textboxPosition: '@',
canShow: '@',
showorhide: '@',
},
template: '<div id="{{ checkId }}" class="form-group" ng-show="true" > ' +
'<label size="lblSize" class="col-sm-{{ labelPosition }} control-label" id="textboxchanges"> Test </label>' +
'<div class="col-sm-{{ textboxPosition }}"> <input type="{{ textboxtype }}" ng-model="ngModel" placeholder="{{ placeHold }}" id="{{checkId}}" class="{{className}}" minlength="{{ ngminLength }}" maxlength="{{ ngmaxLength }}" size="{{ textboxSize }}" ng-required="{{ validate }}" ></div></div>',
link: function(scope, iElement, iAttrs, ngModelController) {
var ngshow = iAttrs.canShow;
var ngsplitValues = ngshow.split(",");
var nglanguage = ngsplitValues[0]; // Language EN or Fr
var nglabelName = ngsplitValues[1]; // Label Name
var ngmoduleName = ngsplitValues[2]; // Module Name (global or local)
telngshowservice.getdata(ngmoduleName).success(function(data) {
scope.showorhide = data[nglabelName];
console.log(scope.showorhide)
})
}
};
}]);
app.factory('telngshowservice', ['$http', function($http) {
var dataFactory = {};
var lang = window.localStorage.language;
dataFactory.getdata = function(moduleName) {
if (moduleName == 'common') {
return $http.get(labeli18nPath + '/translation_' + lang + '.json');
} else {
return $http.get('OPlayout.json');
}
};
return dataFactory;
}]);
【问题讨论】:
-
请告诉我出了什么问题,而无需单击任何链接。你粘贴了一堵代码墙,它有什么问题,你认为问题出在哪里?说明 'ng-show' 在某些较新版本的 Angular 中不起作用并没有真正的帮助。如果它不起作用,您将不会是唯一遇到此问题的人。
-
你有没有做任何事情来缩小问题的范围?
标签: angularjs angularjs-directive