【发布时间】:2014-07-24 16:30:09
【问题描述】:
我对 angularjs 还很陌生,我似乎陷入了代码的扭曲,似乎无法弄清楚这一点。
这里是代码(angularjs)
var siteOptimizeApp = angular.module('siteOptimizeApp', []);
// ---- Controllers ----
siteOptimizeApp.controller('Formctrl',['$scope', '$http', function($scope, $http){
$scope.customer = customer;
$scope.placeholderWrp = '';
$scope.inputWrp = 'hidden';
$scope.modal = 'modal';
$scope.customer.cancelfunc = 'customer.cancel()';
$scope.customer.edit = function(){
$scope.this.placeholderWrp = 'hidden';
$scope.this.inputWrp = '';
}
$scope.customer.cancel = function(){
$scope.this.placeholderWrp = '';
$scope.this.inputWrp = 'hidden';
}
$scope.customer.modal = function(){
}
$scope.formSubmit = function(){
}
}]);
// ---- Directives (element) ---
// remove-btn
siteOptimizeApp.directive('removeBtn', function(){
return {
restrict: 'E',
//replace: true,
scope: {
customerInfo: '=info'
},
template: '<button type="button" class="close" data-dismiss="{{customerInfo}}" ><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>'
}
});
客户在哪里 -
customer = {"birthday":"0000-00-00","customersettings":null,"email":"j_email@gmail.com","fullname":"j_email","gender":"m","cid":"cust_D5C502813C62017","location":"localhost","logintype":"email","timeszone":null}
这里是html:
<form name="profileFrm" action="" novalidate="" ng-controller="Formctrl" ng-submit="formSubmit()">
<div class="modal-header">
<remove-btn info="modal"></remove-btn>
<h4 class="modal-title">Edit Profile</h4>
</div>
<div class="modal-body">
<p class="row">
<label for="fullname" class="col-md-3 col-lg-3 col-sm-12 control-label">Full Name:</label>
<span class="col-md-6 col-lg-6 col-sm-12 form-control-static {{placeholderWrp}}">
{{customer.fullname}}
<a class="edit" href="#" ng-click="customer.edit()" >Edit
<i class="glyphicon glyphicon-edit"></i>
</a>
</span>
<span class="col-md-6 col-lg-6 col-sm-12 form-control-static {{inputWrp}}">
<input ng-model="customer.fullname" class="" id="fullname" type="text" name="fullname" placeholder="Enter Your full name" value="{$fullname}"/>
<remove-btn info="customer.cancelfunc"></remove-btn>
</span>
</p>
</div>
</form>
如您所见,<remove-btn info=""></remove-btn> 是我定义的自定义指令。当我将'info'属性作为'modal'(即'info =“modal”')传递时,它可以正常工作并转换为以下html -
<remove-btn info="modal" class="ng-isolate-scope">
<button type="button" class="close" data-dismiss="modal">
<span aria-hidden="true">×</span>
<span class="sr-only">Close</span>
</button>
</remove-btn>
这基本上是一个用于关闭模式的引导处理按钮。
这是我被卡住的地方: 现在我如何将 ng-click 传递给此自定义指令,以应对 attr 为 'info="modal"'(.i.e' info="somethingelse") 因为我希望能够在整个站点中使用它,并且可能在不同的情况下取消或关闭不同的元素。
【问题讨论】:
标签: javascript jquery html angularjs twitter-bootstrap