I'm trying to get a string turned into an array of strings using .split(n)
, and normally I have no problem with this, but I am encountering a peculiar behavior with angular
's involvement.
I have a model, defined very simply;
var _this = $scope;
_this.model = {
search: {
value: "",
run: function() {}
}
};
Then, I have search.value
bound to an ng-model
attribute on a text field;
<input type="text" id="search-byName"
placeholder="Search"
ng-model="model.search.value"
ng-change="options.search.run()" ng-model-options="{ debounce: 400 }" />
Seems simple enough; Before my controller initializes, I create and attach the run
function.
_this.model.search.run = function() {
console.log('value: ', _this.model.search.value.split(':'));
};
So I initialize the controller and everything, then I start to type any text into the textbox. I'm met with a javascript error;
TypeError: value.split is not a function
Now here is the interesting part, if I do it just a slight bit differently, it works fine.
_this.model.search.run = function() {
var $value = _this.model.search.value;
console.log('value: ', $value.split(':'));
};
Is there a reason, and a workaround, for this behavior?