var app = angular.module('app',[]);
app.controller('selectController',function ($scope) {
$scope.citylist=[{id:1,pop:"北京"},{id:1,pop:"上海"},pop:"广州"}];
$scope.p={};
$scope.cs=function(){
console.log($scope.citylist);
}
}).directive('contenteditable',function() {//自定义ngModel的属性可以用在div等其他元素中
return {
restrict: 'A',// 作为属性使用
require: '?ngModel',// 此指令所代替的函数
link: function(scope,element,attrs,ngModel) {
if (!ngModel) {
return;
} // do nothing if no ng-model
// Specify how UI should be updated
ngModel.$render = function() {
element.html(ngModel.$viewValue || '');
};
// Listen for change events to enable binding
element.on('blur keyup change',function() {
scope.$apply(readViewText);
});
// No need to initialize,AngularJS will initialize the text based on ng-model attribute
// Write data to the model
function readViewText() {
var html = element.html();
// When we clear the content editable the browser leaves a behind
// If strip-br attribute is provided then we strip this out
if (attrs.stripBr && html === ' ') {
html = '';
}
ngModel.$setViewValue(html);
}
}
};
})