I have customized a service that returns the status of a string by passing in numbers
But the value I passed into the input box does not seem to be written correctly. Please help
<p ng-app="app7" ng-controller="myctrl7">
<input type="text" ng-model="txtnum">
<p> {{myservice}}
</p>
</p>
var app7 = angular.module('app7', [])
app7.service('tostring', function () {
this.myfuc = function (x) {
if (x == 1) {
return "未开课"
} else if (x == 2) {
return "已开课"
} else if (x == 3) {
return "已结课"
} else {
return "课程异常"
}
}
})
app7.controller('myctrl7', function ($scope, tostring) {
$scope.myservice = tostring.myfuc($scope.txtnum)
})
This is problematic. Why
When the ngModal of your input changes, myservice will not re-run, because myservice is a difference value on the page. This is a method, not data, so you have to watch and trigger it.