我有一個標題文字和一支鉛筆的圖像:啓用圖像按鈕上點擊/禁用文本Angularjs
這裏是代碼片段:
'use strict';
angular.module('myModule')
.directive('heading', function (messageFormatterUtil, templateHelperService,cartService) {
\t return {
restrict: 'E',
link: function(scope, elem, attrs)
scope.lineId = cartService.allLines[scope.$parent.$index].id;
scope.headingLineContent = templateHelperService.getComponentData(attrs.data).heading;
var title=scope.headingLineContent.title;
scope.headingLineContent = messageFormatterUtil.formatMessage
(title,[scope.$parent.$index + 1]);
scope.$watch('$parent.$index', function() {
scope.lineId = cartService.allLines[scope.$parent.$index].id;
scope.headingLineContent = messageFormatterUtil.formatMessage
(title,[scope.$parent.$index + 1]);
}, true);
\t \t
\t \t scope.view = {
editableValue: scope.headingLineContent,
editorEnabled: false
};
scope.visible = true;
scope.toggle = function() {
scope.visible = scope.visible ? true : false;
};
\t \t \t scope.Open=function() {
scope.view.editorEnabled = true;
scope.view.editableValue = scope.headingLineContent;
var myEl = angular.element(document.querySelector('#line'+scope.lineId));
myEl.attr('title',"true");
};
scope.disableEditor = function() {
scope.view.editorEnabled = false;
};
scope.save = function() {
scope.headingLineContent = scope.view.editableValue;
};
},
templateUrl: './app-modules/cart/views/heading.html'
};
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<span ng-hide="visible" ng-show="show" ng-mouseout="!show" class="m-t-lg m-b-sm inline-block ng-binding">
<input type="text" id="from" />
</span>
<h3 class="m-t-lg m-b-sm inline-block " id="line{{lineId}}" ng-show="!show">{{headingLineContent}}</h3>
<a href="" class="enabled" id="pencilID" ng-click="show = !show"><i class="fa fa-pencil pencil m-l-sm" ng-click="open()" ng-mousedown="save()"></i></a>
Q1 。如何在點擊鉛筆圖像時啓用標題文本(作爲文本字段)? Q2302。當單擊鼠標移出文本字段時,它應該再次轉換爲標題文本,編輯後的值應保存在會話中。